Basic support for PHP and Python fenced code blocks in Markdown
ClosedPublic

Authored by gszymaszek on Sep 17 2017, 7:24 PM.

Details

Summary

This patch enables syntax highlighting of PHP and Python code blocks in Markdown code.

Diff Detail

Repository
R216 Syntax Highlighting
Branch
markdown-code-blocks (branched from master)
Lint
No Linters Available
Unit
No Unit Test Coverage
gszymaszek created this revision.Sep 17 2017, 7:24 PM
Restricted Application added a project: Frameworks. · View Herald TranscriptSep 17 2017, 7:24 PM

Not ready to land, but uploaded per @cfeck’s suggestion (bug 356974).

Could you also extend the test case in
https://github.com/KDE/syntax-highlighting/blob/master/autotests/input/test.markdown

This way, we can automatically guarantee that we will not break this feature accidentally.

gszymaszek updated this revision to Diff 19631.Sep 18 2017, 9:10 AM
  • Removed JavaScript code blocks in Markdown support since it didn’t work
  • Added test cases for new code blocks in Markdown
cullmann added a subscriber: cullmann.

+1, Volker, ok to go in?

This fixes bug https://bugs.kde.org/show_bug.cgi?id=389307 at least partially. More languages such as Ruby etc can still be added.

vkrause accepted this revision.Feb 6 2018, 12:43 PM

Fine with me.
The approach doesn't scale though, so maybe we need to look into better support for this kind of syntax nesting if we want this for many more languages here (similar problems exist in other nest-able languages too).

This revision is now accepted and ready to land.Feb 6 2018, 12:43 PM

@vkrause Do you already have something in mind, when you say this does not scale? ...

This revision was automatically updated to reflect the committed changes.

@vkrause Do you already have something in mind, when you say this does not scale? ...

No concrete ideas yet, but mainly two observations:

  • when nesting a language you need to implement detecting the end of that code manually each time
  • you need to explicitly list all languages you want to nest, one by one

The latter is ok if there is a limited amount of languages that can be nested in this context, but in case of markdown it's in theory every language we have.
So a rule like <NestLanguage syntax="<name or regexp capture>" end="<string|regexp>"/> to do all the repeating work inside the engine might be interesting. We'd need to survey all current usages of nesting to see if that covers enough use-cases though, I haven't done that yet.