! Copyright (C) 2011 John Benediktsson
! See http://factorcode.org/license.txt for BSD license
-USING: help.markup help.syntax sequences strings xmode.catalog
-xmode.highlight xmode.tokens ;
+USING: help.markup help.syntax sequences strings words
+xmode.catalog xmode.highlight xmode.tokens ;
IN: xmode.highlight
} ;
HELP: highlight.
-{ $values { "path" string } }
+{ $values { "obj" string } }
{ $description
- "Highlight and print code from the specified file (represented by "
- { $snippet "path" } "). The mode is determined using the file extension."
+ "Highlight and print code from the specified " { $link word } " or path (with a mode determined using the file extension)."
} ;
! Copyright (C) 2011 John Benediktsson
! See http://factorcode.org/license.txt for BSD license
-USING: accessors assocs colors.hex io io.encodings.utf8 io.files
-io.styles kernel locals math math.parser namespaces sequences
-xmode.catalog xmode.marker ;
+USING: accessors assocs colors.hex io io.encodings.utf8
+io.files io.streams.string io.styles kernel locals see
+sequences splitting strings words xmode.catalog xmode.marker ;
IN: xmode.highlight
: highlight-tokens ( tokens -- )
[
[ str>> ] [ id>> ] bi
- [ name>> STYLES at ] [ f ] if* BASE assoc-union
+ [ name>> STYLES at BASE assoc-union ] [ BASE ] if*
format
] each nl ;
tokenize-line highlight-tokens
] curry each drop ;
-:: highlight. ( path -- )
+GENERIC: highlight. ( obj -- )
+
+M:: string highlight. ( path -- )
path utf8 file-lines [
path over first find-mode highlight-lines
] unless-empty ;
+
+M: word highlight.
+ [ see ] with-string-writer string-lines
+ "factor" highlight-lines ;