Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion integrations/logseq-native-modes/lang-haml-slim/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ modern language API and syntax-tree highlighter.
wrapped and bare attributes, Ruby switches and interpolation, and indented
text and Ruby regions. Wrapped attribute lists can span lines in both
languages, including HAML's parenthesized attributes.
- Filters other than Ruby and HTML or HAML's preserve filter are plain text.
- Slim's JavaScript and CSS filters mount the corresponding native grammars.
Other filters beyond Ruby, HTML, and HAML's preserve filter are plain text.
Individual Ruby attribute values are line-local. Spaces in a value are
supported inside strings and balanced brackets. At the top level a space ends
the value.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@ val slim :
?base:Codemirror_ml_language.Language.Support.t ->
unit ->
Codemirror_ml_language.Language.Support.t
(** Highlight Slim and parse embedded markup using the base (HTML by default).
*)
(** Highlight Slim and its JavaScript and CSS filters. Embedded markup uses the
base language (HTML by default). *)
2 changes: 2 additions & 0 deletions integrations/logseq-native-modes/lang-haml-slim/dune
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
(modes native)
(libraries
codemirror-ml.lang-html
codemirror-ml.lang-css
codemirror-ml.lang-javascript
codemirror-ml.language
logseq-native-modes.legacy-modes
codemirror-ml.lezer_common
Expand Down
4 changes: 3 additions & 1 deletion integrations/logseq-native-modes/lang-haml-slim/slim.ml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ let filter line =
match name line ~offset:0 ~length:size with
| "ruby" -> Some (size, Ruby)
| "html" -> Some (size, Html)
| "javascript" | "css" | "sass" | "scss" | "less" | "styl" | "coffee"
| "javascript" -> Some (size, Javascript)
| "css" -> Some (size, Css)
| "sass" | "scss" | "less" | "styl" | "coffee"
| "asciidoc" | "markdown" | "textile" | "creole" | "wiki" | "mediawiki"
| "rdoc" | "builder" | "nokogiri" | "erb" | "plain" ->
Some (size, Text)
Expand Down
29 changes: 21 additions & 8 deletions integrations/logseq-native-modes/lang-haml-slim/template.ml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ let comment_region = node "CommentRegion" 8 []
let text_region = node "TextRegion" 9 []
let html_region = node "HtmlRegion" 10 []
let ruby_region = node "RubyRegion" 11 []
let javascript_region = node "JavaScriptRegion" 12 []
let css_region = node "CSSRegion" 13 []

let ruby_types =
let open Highlight.Tags in
Expand All @@ -51,7 +53,7 @@ let ruby_types =
|> List.mapi (fun i (style, name, tag) -> (style, node name (20 + i) [ tag ]))

type mark = Tag | Attribute | Keyword | Marker | Comment
type body = Comments | Text | Html | Ruby
type body = Comments | Text | Html | Ruby | Javascript | Css
type action = Finish | Indented of body | Following_text of int | Ruby_line
type ruby = { state : Ruby_mode.state; mutable closes : char list }
type ruby_group = { ruby : ruby; closing : char }
Expand Down Expand Up @@ -277,6 +279,8 @@ let region_type = function
| Text -> text_region
| Html -> html_region
| Ruby -> ruby_region
| Javascript -> javascript_region
| Css -> css_region

let column line =
let rec columns i width =
Expand Down Expand Up @@ -474,6 +478,15 @@ let language ?(after_group = fun _ -> Finish) ~name ~comment rule =

let default_html = lazy (Codemirror_ml_lang_html.html ())

let javascript_parser =
Language.Lr_language.language
Codemirror_ml_lang_javascript.javascript_language
|> Language.parser

let css_parser =
Language.Lr_language.language Codemirror_ml_lang_css.css_language
|> Language.parser

let with_html template base =
let base =
match base with Some base -> base | None -> Lazy.force default_html
Expand All @@ -484,13 +497,13 @@ let with_html template base =
in
let wrap =
Mix.parse_mixed (fun node _ ->
if Node_type.is_top (Syntax_node.node_type node) then
Some
{
Mix.parser;
overlay = Some (Mix.Predicate overlay);
bracketed = false;
}
let type_ = Syntax_node.node_type node in
if Node_type.is_top type_ then
Some { Mix.parser; overlay = Some (Mix.Predicate overlay); bracketed = false }
else if type_ == javascript_region then
Some { Mix.parser = javascript_parser; overlay = None; bracketed = false }
else if type_ == css_region then
Some { Mix.parser = css_parser; overlay = None; bracketed = false }
else None)
in
let mixed = Parser.with_wrapper (Language.parser template) wrap in
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

type line
type mark = Tag | Attribute | Keyword | Marker | Comment
type body = Comments | Text | Html | Ruby
type body = Comments | Text | Html | Ruby | Javascript | Css
type action = Finish | Indented of body | Following_text of int | Ruby_line

val peek : ?offset:int -> line -> char -> bool
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,4 +119,9 @@ let () =
(43, 53, "attribute"); (54, 63, "string"); (72, 75, "property");
(105, 107, "tag") ],
[ (92, 104) ] );
]
];
check "Slim JavaScript and CSS filters" (Provider.slim ())
("javascript:\r\n const icon = \"😀\";\r\n\r\n const count = 42;\r\n"
^ "css:\r\n .icon { color: red; }\r\np <em>done</em>\r\n")
[ (15, 20, "keyword"); (28, 32, "string"); (53, 55, "number");
(74, 79, "property"); (89, 90, "tag"); (92, 94, "tag") ]
Loading