YAML: add literal & folded block styles
ClosedPublic

Authored by nibags on Sep 26 2018, 7:45 PM.

Details

Summary

Highlight literal blocks after the operators |, |-, |+, >, >- and >+.

To do this correctly, the indentation of the Key or operator is captured (with dynamic rules). Note that in nested block collections, the - and ? characters are considered as part of the indentation (ref. [2] & [3]):

  • With Key: Text lines with indentation of the Key plus a space are considered literal. The - and ? operators are considered as part of the indentation:

  • If there is no Key present: the literal/folded operator is at the beginning of the line or there is - or ? character before. In the first case, the indentation of the literal/folded operator is captured and, in the second, the indentation of - or ?. In nested blocks or sequences, the indentation of the last operator ? or - is captured:

  • But, this implementation has a limitation: it only supports 6 nested operadors (? and -) at most.

This only works with indentations with spaces. If a tab is detected, it is highlighted with "Alert".
The empty lines are also part of the literal block.

Also, some minor improvements are included: the sequences require a dash plus a space.

Source:
YAML 1.2 Specs:

BUG: 398314
FIXED-IN: 5.51.0

Test Plan

Diff Detail

Repository
R216 Syntax Highlighting
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.
nibags created this revision.Sep 26 2018, 7:45 PM
Restricted Application added projects: Kate, Frameworks. · View Herald TranscriptSep 26 2018, 7:45 PM
Restricted Application added subscribers: kde-frameworks-devel, kwrite-devel. · View Herald Transcript
nibags requested review of this revision.Sep 26 2018, 7:45 PM
nibags edited the summary of this revision. (Show Details)Sep 26 2018, 7:53 PM
nibags edited the test plan for this revision. (Show Details)
nibags retitled this revision from YAML: add support for literal & folded block styles to YAML: add literal & folded block styles.Sep 26 2018, 8:12 PM

I cannot really say much about it, since I never use YAML. Still, if the unit test works, then I am fine with this.

+1 from my side. Anyone else with a +2?

turbov accepted this revision.Sep 27 2018, 12:31 AM
turbov added a subscriber: turbov.

Good job!

@dhaumann,

my +1

This revision is now accepted and ready to land.Sep 27 2018, 12:31 AM
nibags edited the summary of this revision. (Show Details)Sep 28 2018, 3:21 AM
This revision was automatically updated to reflect the committed changes.