Skip to content

Commit

Permalink
Implement Special Sections
Browse files Browse the repository at this point in the history
* Add to syntax support for special section styles,
  under the `one_liners_sq-bracketed` context (see #53).
* Add to "AsciiDoc Dark" color scheme a rule to color special sections.
* Remove a redundant inclusion of `attribute_list_line` in `one_liners`
  context, since it's already part of the `one_liners_sq-bracketed`.
* Move inclusion of `one_liners_sq-bracketed` at the top of `one_liners`
  context, because it should be give higher priority due to the vast
  number of constructs it covers, and their usage frequency (see #53).
  • Loading branch information
tajmone committed Feb 26, 2024
1 parent cd2538c commit 031da03
Show file tree
Hide file tree
Showing 3 changed files with 238 additions and 38 deletions.
6 changes: 6 additions & 0 deletions Color-Schemes/AsciiDoc Dark.sublime-color-scheme
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,12 @@
"scope": "constant.character.entity",
"foreground": "var(orange)",
},
// Special Sections Styles
{
"name": "Special Sections: Style name",
"scope": "support.constant.sectionstyle",
"foreground": "dodgerblue",
},
// Callouts
{
"name": "Callout: Brackets (< >)",
Expand Down
95 changes: 57 additions & 38 deletions Syntaxes/Asciidoctor.sublime-syntax
Original file line number Diff line number Diff line change
Expand Up @@ -1219,13 +1219,12 @@ contexts:
# Try to keep them in order of importance (most common first):

one_liners:
- include: one_liners_sq-bracketed # keep first! (i.e. all '[...]' elements)
- include: line_comment
- include: list_continuation
- include: inline_break # Not a single-liner! Move to reusables!
- include: block_title
- include: attribute_entry
- include: attribute_list_line
- include: one_liners_sq-bracketed # i.e. all '[...]' elements
- include: block_page_break
- include: block_thematic_break

Expand Down Expand Up @@ -1473,11 +1472,67 @@ contexts:
# ensure that RegEx pattern consume them without scoping them.

one_liners_sq-bracketed:
- include: special_section # keep first!
- include: block_id_legacy
- include: attribute_list_line # keep last! (generic fallback)
# - include: block_req # <- ADDED by @bsmith-n4
# - include: section_template

##################
# SPECIAL SECTIONS
##################
# Built-in "special sections" for specialized front- and back-matter sections
# for articles and/or books.
# Example:
# [appendix]
# == First Appendix

# abstract, acknowledgments, appendix, bibliography,
# colophon, dedication, glossary, index, preface.

special_section:
# I couldn't think of better scope names, but 'support.constant' seems to
# make sense here since they are hard-wired values; I didn't like the
# original 'sectiontemplate' scope, and opted for 'sectionstyle' instead.
# The original syntax didn't scope the actual style name, it just relied
# on the outer 'meta' scoping.
- match: '^(?x)((\[)(
abstract|acknowledgments|appendix|bibliography|
colophon|dedication|glossary|index|partintro|preface
)(\]))\s*$\n?'
captures:
1: meta.tag.sectionstyle.asciidoc
2: punctuation.definition.sectionstyle.begin.asciidoc
3: support.constant.sectionstyle.asciidoc
4: punctuation.definition.sectionstyle.end.asciidoc

# TODO: Asciidoctor DOES support the alternative quoted syntax:
#
# ["appendix"]
#
# So we'll need to implement it, even though is less idiomatic.

# NOTE: Asciidoctor DOES NOT support AsciiDoc Python template syntax, e.g.:
#
# [template="appendix"]
#
# The original package supported it, but we dropped it since Asciidoctor
# doesn't (probably deprecated, maybe was never standard).
# For more info, see AsciiDoc Python documentation:
# https://asciidoc-py.github.io/chunked/ch08.html#_sections

# TODO: Some converters also support the 'notitle' option, which can only be
# set on special sections; e.g.:
#
# [dedication%notitle]
#
# with alternative 'opts=notitle' syntax, and maybe the old option name
# 'untitled' too. The problem is that I can't test any of these since
# the HTML backend of Asciidoctor Ruby just ignores them.
# Currently, this seem to work with the DocBook backend only. See:
# https://docs.asciidoctor.org/asciidoc/latest/sections/special-section-titles/


##########################
# BLOCK ID (legacy syntax)
##########################
Expand Down Expand Up @@ -1514,42 +1569,6 @@ contexts:
3: punctuation.definition.attributelistline.end.asciidoc


##################
# SECTION TEMPLATE [TBD!]
##################
# Fixed list of known template names
# See: §16.9. Section Styles
# https://asciidoctor.org/docs/user-manual/#section-styles

# IMPORTANT: This element differs in @bsmith-n4 and original!
#
# section_template:
# comment: fixed list of known template names
# name: variable.parameter.sectiontemplate.asciidoc
# match: |-



# >>>>>>>>>>>>>>>>>>>>>>>>>>>
# section_template:
# comment: fixed list of known template names
# name: variable.parameter.sectiontemplate.asciidoc
# match: | # <- CHANGED by @bsmith-n4 (was: match: |-)
# (?x)^
# (\[) # in square brackets
# (template\s*=\s*)?(")? # might start with template-equals and might have template name in quotes
# (
# sect\d|abstract|preface|colophon|dedication|glossary|bibliography|synopsis|appendix|index # fixed list of known templates
# )
# (".*(\])|(\])) # either close the quote (and perhaps go on) and close the bracket, or close the bracket immediately
# \s*$\n?
# captures:
# '1': {name: punctuation.definition.sectiontemplate.begin.asciidoc}
# '4': {name: meta.tag.sectiontemplate.asciidoc}
# '6': {name: punctuation.definition.sectiontemplate.end.asciidoc}
# '7': {name: punctuation.definition.sectiontemplate.end.asciidoc}
# <<<<<<<<<<<<<<<<<<<<<<<<<<<

#*******************************************************************************
# *
# L I S T S *
Expand Down
175 changes: 175 additions & 0 deletions Tests/syntax_test_Special-Sections-Book.asciidoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
// SYNTAX TEST "Packages/ST4-Asciidoctor/Syntaxes/Asciidoctor.sublime-syntax"
= Special Sections for Book
:doctype: book

Test special section style for `book` document type, which covers all the available section styles (unlike `article` documents).

AsciiDoc Documentation reference:
https://docs.asciidoctor.org/asciidoc/latest/sections/styles/[Section Styles for Articles and Books^]

****
AsciiDoc provides built-in styles for the specialized front matter and back matter sections found in journal articles, academic papers, and books.
These styled sections are referred to as *special sections*.
The document type, `article` or `book`, determines which section styles are available for use.
****

[NOTE]
===================
This begin a `book` document, it requires setting up Parts contexts to cover all book special sections while remaining a well formed AsciiDoc document that passes the Rake build.
It's a more verbose approach, but it allows us to test all existing section styles in a single document, since `article` documents support only a subset of special sections.
===================

[WARNING]
===================
Currently the syntax of our package doesn't support the `notitle` option (e.g., `%notitle` or `opts=notitle`) which allows to turn off the title of a special section in those converters that supports it:
* https://docs.asciidoctor.org/asciidoc/latest/sections/special-section-titles/[Hide Special Section Titles^]
.Option `notitle` Example
[source,asciidoc]
--------------------
[dedication%notitle]
== Dedication
--------------------
It seems that this feature is currently only supported by the DocBook backend.
In any case, in the future we should add support for it, so that its presence doesn't prevent correct highlighting and scoping of special sections.
===================

// =============================================================================
// COLOPHON
// =============================================================================
////
Since this is the first test, we'll be more thorough in covering the scope of
every character, checking that scopes don't spill, etc. In further tests we'll
just focus on fewer details...
////
[colophon]
//<- meta.tag.sectionstyle
//^^^^^^^^ meta.tag.sectionstyle
// ^ -meta.tag.sectionstyle
//<- punctuation.definition.sectionstyle.begin
//^^^^^^^ support.constant.sectionstyle
// ^ -support.constant.sectionstyle
// ^ punctuation.definition.sectionstyle.end
== Colophon

The ST4 Asciidoctor "`Syntax Tests Suite`".

(C) 2024 by Tristano Ajmone.

// =============================================================================
// DEDICATION
// =============================================================================
[dedication]
//^^^^^^^^^ support.constant.sectionstyle
// ^ -meta.tag.sectionstyle
= Dedication

This test is dedicated to @polyglot-jones for all his support and contributions.

// =============================================================================
// ACKNOWLEDGMENTS
// =============================================================================
[acknowledgments]
//^^^^^^^^^^^^^^ support.constant.sectionstyle
// ^ -meta.tag.sectionstyle
== Acknowledgments

Thanks to the SublimeText and Asciidoctor online communities for all their support.


= Part One

_The Pragmatic Programmer_ <<pp>> should be required reading for all developers.
To learn all about design patterns, refer to the book by the "`Gang of Four`" <<gof>>.

// =============================================================================
// ABSTRACT
// =============================================================================
[abstract]
//<- meta.tag.sectionstyle
//<- punctuation.definition.sectionstyle.begin
//^^^^^^^ support.constant.sectionstyle
// ^ punctuation.definition.sectionstyle.end
== Abstract (Section)

The `abstract` section in a book becomes a chapter.

See also AsciiDoc Documentation for `abstract` block (currently untested here):

* https://docs.asciidoctor.org/asciidoc/latest/sections/abstract-block/[Abstract (Block)^]


= Part Two

// =============================================================================
// PARTINTRO
// =============================================================================
[partintro]
//^^^^^^^^ support.constant.sectionstyle
--
This is an explicit `partintro` (must be first child of part), wrapped in an open block -- although it would be implicitly so even without the special section style:

* https://docs.asciidoctor.org/asciidoc/latest/sections/parts/#part-intro[AsciiDoc Manual » Part intro^]
--

// =============================================================================
// PREFACE
// =============================================================================
[preface]
//^^^^^^ support.constant.sectionstyle
// ^ punctuation.definition.sectionstyle.end
== Part Two Preface

Book Parts can have their `preface` too.

// =============================================================================
// APPENDIX
// =============================================================================
[appendix]
//^^^^^^^ support.constant.sectionstyle
= Appendix One

Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua.


// =============================================================================
// GLOSSARY
// =============================================================================
[glossary]
//^^^^^^^ support.constant.sectionstyle
== Glossary

In addition to setting `glossary` on the section, the block style `glossary` must be set on the description list in the section.

[glossary]
mud:: wet, cold dirt
rain::
water falling from the sky

// =============================================================================
// BIBLIOGRAPHY
// =============================================================================
[bibliography]
//^^^^^^^^^^^ support.constant.sectionstyle
= Bibliographic References

* [[[pp]]] Andy Hunt & Dave Thomas. The Pragmatic Programmer:
From Journeyman to Master. Addison-Wesley. 1999.
* [[[gof,gang]]] Erich Gamma, Richard Helm, Ralph Johnson & John Vlissides.
Design Patterns: Elements of Reusable Object-Oriented Software. Addison-Wesley. 1994.

// =============================================================================
// INDEX
// =============================================================================
[index]
//^^^^ support.constant.sectionstyle
== Index

WARNING: The built-in HTML5 converter in Asciidoctor does not generate an index.


// EOF //

0 comments on commit 031da03

Please sign in to comment.