JavaFX Codeeditors – New features for Scanner rules (required to support eg Asciidoc)


Yesterday I worked on a cool addition required to develop syntax highlighting for things like Asciidoc.

screen-with-preview

Suppose you want to define lexical highlighting for Asciidoc you very likely have a rule like this:

lexical_highlighting {
  // ...
  rule __dftl_partition_content_type whitespace javawhitespace {
    // ...
    adoc_section_0 {
      single_line "= "
    }
    // ...
  }
  // ...
}

But now suppose your asciidoc-File looks like this:

= This is a head line
if a = b you're doing something wrong

the above rule would produce the following highlighting

ascii-wrong

which obivously is wrong. What our rule really has to express is

if a line starts with = (equal-sign) followed by a space

So the new addition I added the the ldef-DSL is that you can now define at which column in a line the rule has to start

lexical_highlighting {
  // ...
  rule __dftl_partition_content_type whitespace javawhitespace {
    // ...
    adoc_section_0 {
      single_line "= " col eq 0
    }
    // ...
  }
  // ...
}

and now the result looks ok

ascii-correct

2 thoughts on “JavaFX Codeeditors – New features for Scanner rules (required to support eg Asciidoc)

  1. jmini September 22, 2015 / 9:32 am

    Thanks a lot, I have crossposted this information (with some context) to the Asciidoctor ML:
    http://discuss.asciidoctor.org/How-can-we-make-better-AsciidocFX-td3109.html#a3745

    There is already a JavaFX tool called “AsciidocFX” to work on Asciidoc files. Maybe they should use your StyledTextArea component.

    With this extension, is it possible to build a “Compensator” tool to edit and preview Asciidoc files? From the screenshot I guess you have something like that.

    Are the sources availlable? Or even better for me an exe to test?

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s