Skip to content

Commit

Permalink
Org: Keep all newlines (#951)
Browse files Browse the repository at this point in the history
- Move the `*` operator to inside the capturing group so all characters
that match `\s` is preserved and not just the first character.
- Add tests.
- Resolves #845

<details><summary>Input</summary>

```orgmode
Generic text.

/Italicized/

*strong*

=Heading=

~Codeblock~

+StrikeTrough+

_Underlined_
```

</details>

## Before
![Screen Shot 2024-04-01 at 23 26
15](https://github.com/alecthomas/chroma/assets/25481501/0ddc4b34-c434-4798-9b2a-0773b2be4f05)

## After
![Screen Shot 2024-04-01 at 23 25
52](https://github.com/alecthomas/chroma/assets/25481501/ad46591d-8d3c-421e-8564-d3d36abe6fa1)
  • Loading branch information
Gusted authored Apr 1, 2024
1 parent d07caa4 commit e5c25d0
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 8 deletions.
12 changes: 6 additions & 6 deletions lexers/embedded/org_mode.xml
Original file line number Diff line number Diff line change
Expand Up @@ -228,42 +228,42 @@
</rule>
</state>
<state name="inline">
<rule pattern="(\s)*(\*[^ \n*][^*]+?[^ \n*]\*)((?=\W|\n|$))">
<rule pattern="(\s*)(\*[^ \n*][^*]+?[^ \n*]\*)((?=\W|\n|$))">
<bygroups>
<token type="Text"/>
<token type="GenericStrong"/>
<token type="Text"/>
</bygroups>
</rule>
<rule pattern="(\s)*(/[^/]+?/)((?=\W|\n|$))">
<rule pattern="(\s*)(/[^/]+?/)((?=\W|\n|$))">
<bygroups>
<token type="Text"/>
<token type="GenericEmph"/>
<token type="Text"/>
</bygroups>
</rule>
<rule pattern="(\s)*(=[^\n=]+?=)((?=\W|\n|$))">
<rule pattern="(\s*)(=[^\n=]+?=)((?=\W|\n|$))">
<bygroups>
<token type="Text"/>
<token type="NameClass"/>
<token type="Text"/>
</bygroups>
</rule>
<rule pattern="(\s)*(~[^\n~]+?~)((?=\W|\n|$))">
<rule pattern="(\s*)(~[^\n~]+?~)((?=\W|\n|$))">
<bygroups>
<token type="Text"/>
<token type="NameClass"/>
<token type="Text"/>
</bygroups>
</rule>
<rule pattern="(\s)*(\+[^+]+?\+)((?=\W|\n|$))">
<rule pattern="(\s*)(\+[^+]+?\+)((?=\W|\n|$))">
<bygroups>
<token type="Text"/>
<token type="GenericDeleted"/>
<token type="Text"/>
</bygroups>
</rule>
<rule pattern="(\s)*(_[^_]+?_)((?=\W|\n|$))">
<rule pattern="(\s*)(_[^_]+?_)((?=\W|\n|$))">
<bygroups>
<token type="Text"/>
<token type="GenericUnderline"/>
Expand Down
14 changes: 14 additions & 0 deletions lexers/testdata/org.actual
Original file line number Diff line number Diff line change
Expand Up @@ -143,3 +143,17 @@ manual/Footnotes.html][page for footnotes]].
# Local Variables:
# org-link-file-path-type: relative
# End:

Generic text.

/Italicized/

*strong*

=Heading=

~Codeblock~

+StrikeTrough+

_Underlined_
15 changes: 13 additions & 2 deletions lexers/testdata/org.expected
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
{"type":"NameClass","value":"=EXPORT_FILE_NAME="},
{"type":"Text","value":"\nproperty in here. But then you also lose the tag and property\ninheritance Org awesomeness.\n\nline one "},
{"type":"Operator","value":"\\\\"},
{"type":"Text","value":"\nline two\n"},
{"type":"Text","value":"\nline two\n\n"},
{"type":"GenericStrong","value":"*bold*"},
{"type":"Text","value":" "},
{"type":"GenericEmph","value":"/italics/"},
Expand Down Expand Up @@ -361,5 +361,16 @@
{"type":"Comment","value":"# org-link-file-path-type: relative"},
{"type":"Text","value":"\n"},
{"type":"Comment","value":"# End:"},
{"type":"Text","value":"\n"}
{"type":"Text","value":"\n\nGeneric text.\n\n"},
{"type":"GenericEmph","value":"/Italicized/"},
{"type":"Text","value":"\n\n"},
{"type":"GenericStrong","value":"*strong*"},
{"type":"Text","value":"\n\n"},
{"type":"NameClass","value":"=Heading="},
{"type":"Text","value":"\n\n"},
{"type":"NameClass","value":"~Codeblock~"},
{"type":"Text","value":"\n\n"},
{"type":"GenericDeleted","value":"+StrikeTrough+"},
{"type":"Text","value":"\n\n"},
{"type":"GenericUnderline","value":"_Underlined_"}
]

0 comments on commit e5c25d0

Please sign in to comment.