Skip to content

Instantly share code, notes, and snippets.

@mojavelinux
Created December 19, 2012 01:26
Show Gist options
  • Select an option

  • Save mojavelinux/4333661 to your computer and use it in GitHub Desktop.

Select an option

Save mojavelinux/4333661 to your computer and use it in GitHub Desktop.
First cut at declarative parser and renderer information for Asciidoctor.
:admonition_styles: &ADMONITION_STYLES [NOTE, TIP, IMPORTANT, WARNING, CAUTION]
:default_doctype: article
:default_backend: html5
:headings:
:oneline:
# examples:
#
# = Document Title
#
# == First Section ==
:lines: 1
:levels: ['=', '==', '===', '====', '=====']
:pattern: !ruby/regexp '/^(={1,5})\s+(\S.*?)\s*(\s\1)?$/'
:twoline:
# examples:
#
# Document Title
# ==============
#
# First Section
# -------------
:lines: 2
:levels: ['=', '-', '~', '^', '+']
:patterns:
- !ruby/regexp '/^\s*.*\w.*\s*$/'
- !ruby/regexp '/^([=\-~^\+]){2,}\s*$/'
# NOTE: process block macros first, in order, then blockmeta, in order, then blocks, in order
:blocks:
:comment:
# examples:
#
# ////
# block comment
# ////
:auto: true
:style: comment
:delimiter:
:char: '/'
:pattern: !ruby/regexp '/^\/{4,}\s*$/'
:skip: true
:sidebar:
# examples:
#
# ****
# Sidebar
# ****
:auto: true
:style: sidebar
:posattrs: [style]
:delimiter:
:char: '*'
:pattern: !ruby/regexp '/^\*{4,}\s*$/'
:section_body: true
:example:
# examples:
#
# ====
# Example
# ====
#
# [NOTE]
# ====
# Multi-paragraph...
#
# ...note.
# ====
:auto: true
:style: example
#:alt_styles: *ADMONITION_STYLES
:posattrs: [style]
:delimiter:
:char: '='
:pattern: !ruby/regexp '/^={4,}\s*$/'
:section_body: true
:listing:
# examples:
#
# ----
# code here
# ----
#
# [source, ruby]
# ----
# puts "Program happy!"
# ----
:auto: true
:style: listing
:posattrs: [style, language, linenums]
:delimiter:
:char: '-'
:pattern: !ruby/regexp '/^-{4,}\s*$/'
:section_body: false
:subs: [specialchars, callouts]
# this could also be verbatim, then imply it
:postprocess: [chomp_last]
:literal:
# examples:
#
# ....
# literally
# ....
:auto: true
:style: literal
:alt_styles: [listing]
:posattrs: [style]
:delimiter:
:char: '.'
:pattern: !ruby/regexp '/^\.{4,}\s*$/'
:section_body: false
:subs: [specialchars]
:postprocess: [chomp_last]
:quote:
# examples:
#
# [quote, Sir Arthur Conan Doyle, The Adventures of Sherlock Holmes]
# ____
# When you have eliminated all which is impossible, then whatever remains, however improbable, must be the truth.
# ____
#
# [verse]
# ____
# La la la
#
# La la la
# ____
:auto: true
:style: quote
:alt_styles: [verse]
:posattrs: [style, attribution, citetitle]
:delimiter:
:char: '_'
:pattern: !ruby/regexp '/^_{4,}\s*$/'
:section_body: true
:subs: [attributes, strip, htmlify]
# TODO could get to verse via reference from quote
:verse:
:style: verse
:section_body: false
:subs: [attributes]
:admonition:
:subs: [attributes]
:pass:
:auto: true
:style: pass
:posattrs: [style]
:delimiter:
:char: '+'
:pattern: !ruby/regexp '/^\+{4,}\s*$/'
:section_body: false
:subs: []
:open:
:style: default
:alt_styles: '*'
:posattrs: [style]
:delimiter:
:char: '-'
:pattern: !ruby/regexp '/^-{2,}\s*$/'
:literalparagraph:
# Examples:
#
# Indented by at least one character.
#
# Multiple lines
# will be joined as one block
:style: literal
:posattrs: [style]
:postprocess: [chomp_last]
:paragraph:
# Examples:
#
# Paragraph one.
#
# Paragraph two.
:style: normal
:alt_styles: '*'
:posattrs: [style]
:delimiter:
:pattern: !ruby/regexp '/^\S.*$/'
:break_on_blank_lines: true
:section_body: false
:blockmeta:
:single:
:anchor:
# examples:
#
# [[defs]]
:pattern: !ruby/regexp '/^\[\[([^\[\]]+)\]\]\s*$/'
:validate_pattern: !ruby/regexp '/^[:_a-z][-\.:_a-z0-9]*$/i'
:reference: true
:assignments:
-
# this should probably set id attribute instead
:type: local
:capture_group: 1
:target: anchor
:multiple:
:attributes:
# examples:
#
# [quote, Adam Smith, Wealth of Nations]
#
# [NOTE, caption="Good to know"]
:pattern: !ruby/regexp '/^\[(\w.*)\]$/'
:capture:
:attributes: 1
:title:
# examples:
#
# .Title
# ! . Title
# ! ..Title
:pattern: !ruby/regexp '/^\.([^\s\.].*)\s*$/'
:assignments:
-
:type: local
:capture_group: 1
:target: title
:lists:
:ulist:
# examples:
#
# * Item
# - Item
# ! *Item
# ! -Item
:pattern: !ruby/regexp '/^\s*(-|\*{1,5})\s+(.*)\s*$/'
:olist:
# examples:
#
# . Item
# 1.Item
# 1. Item
:pattern: !ruby/regexp '/^\s*(\d+\.|\. )(.*)$/'
:dlist:
# examples
#
# term:: def
# term::
# def
# term::
# def
# term;; def
# term::: def
# term:::: def
:pattern: !ruby/regexp '/^\s*(?:\[\[([^\]]*)\]\])?(\w.*?)(:{2,4}|;;)(\s+(.*))?$/'
:sibling_patterns:
'::': '/^\s*(?:\[\[([^\]]*)\]\])?(\w(?:.*[^:])?)(::)(\s+(.*))?$/'
':::': '/^\s*(?:\[\[([^\]]*)\]\])?(\w(?:.*[^:])?)(:::)(\s+(.*))?$/'
'::::': '/^\s*(?:\[\[([^\]]*)\]\])?(\w(?:.*[^:])?)(::::)(\s+(.*))?$/'
';;': '/^\s*(?:\[\[([^\]]*)\]\])?(\w.*)(;;)(\s+(.*))?$/'
:colist:
:pattern: !ruby/regexp '/^(\<\d+\>)\s*(.*)/'
:macros:
:block:
:comment:
# examples:
#
# // line comment
# //line comment w/o a leading space
:pattern: !ruby/regexp '/^\/\/([^\/].*|)$/'
:skip: true
:ruler:
# examples:
#
# '''
:pattern: !ruby/regexp '/^''{3,}\s*$/'
:image:
# examples:
#
# image::tiger.png[Tiger]
:pattern: !ruby/regexp '/^image::(\S+?)\[(.*?)\]$/'
:posattrs: [alt, width, height]
:capture:
:attributes: 2
:attributes:
target: 1
:attributes:
startsb: '['
endsb: ']'
brvbar: '|'
caret: '^'
asterisk: '*'
tilde: '~'
litdd: '--'
plus: '+'
apos: ''''
backslash: '\'
backtick: '`'
empty: ''
sp: ' '
'two-colons': '::'
'two-semicolons': ';;'
nbsp: '&#160;'
deg: '&#176;'
zwsp: '&#8203;'
lsquo: '&#8216;'
rsquo: '&#8217;'
ldquo: '&#8220;'
rdquo: '&#8221;'
wj: '&#8288;'
amp: '&'
lt: '<'
gt: '>'
:subs:
:special:
'<': '&lt;'
'>': '&gt;'
'&': '&amp;'
:replacements:
-
:pattern: !ruby/regexp '/\(C\)/'
:text: '&#169;'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment