Skip to content

Instantly share code, notes, and snippets.

@kongou-ae
Last active December 29, 2016 17:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kongou-ae/7c2b2673bd67b04ab616bd6b4e6a9af1 to your computer and use it in GitHub Desktop.
Save kongou-ae/7c2b2673bd67b04ab616bd6b4e6a9af1 to your computer and use it in GitHub Desktop.
asciidoctor ast format
= レベル1

レベル1本文

== レベル2

レベル2本文その1

レベル2本文その2

* 1
* 2
** 1.1
** 1.2

=== レベル3

レベル3本文その1

レベル3本文その2

asciidoc.parse().reader.document

ざっくりとした構造

document
|--header
|--blocks[Array]
    [preamble]
       |--blocks[Array]
       |   [paragraph]
    [section]
       |--blocks[Array]
           [paragraph]
           [paragraph]
           [ulist]
              |--blocks[Array]
              |   [list_item]
              |   [list_item]
           [section]
              |--blocks[Array]
                  [paragraph]
                  [paragraph]

使えそうな要素

document

  • reader 全要素
  • reader.source_lines 全文
  • reader.lineno 全文の行数のようだが、15行に対して517となる。

header

  • header ヘッダ=H1要素
  • header.node_name この要素の区分
  • header.title
  • header.level 階層?0
  • header.source_location.lineno ソースの中の行数
  • header.index なんだろう?
  • header.number なんだろう?

block

  • blocks H1以降の全要素。配列。
  • blocks[n] 個々の要素
  • blocks[n].node_name がpreambleの場合、さらにblocksが入っている。
  • blocks[n].level 階層
  • blocks[n].index 0
  • blocks[n].number 1 preambleの場合は存在しない

section

ヘッダと同じ扱い

  • blocks[1].title
  • blocks[1].level 階層?1
  • blocks[1].source_location.lineno ソースの中の行数
  • blocks[1].index なんだろう?0
  • blocks[1].number なんだろう?1
  • blocks[1].node_name
  • blocks[1].subbed_title blocks[1].titleと同じ

paragraph

indexとnumberがない

  • blocks[1].blocks[0].node_name
  • blocks[1].blocks[0].level
  • blocks[1].blocks[0].source_location
  • blocks[1].blocks[0].lines 配列。文章が入ってる

ulist / olist

  • blocks[1].blocks[2].blocks リストのアイテムが入ってる
  • blocks[1].blocks[2].node_name
  • blocks[1].blocks[2].level
  • blocks[1].blocks[2].source_location.lineno 11 リストのスタート行

list_item

  • blocks[1].blocks[2].blocks[0].node_name list_item
  • blocks[1].blocks[2].blocks[0].text 1
  • blocks[1].blocks[2].blocks[0].marker *
  • blocks[1].blocks[2].blocks[0].level
  • blocks[1].blocks[2].blocks[0].source_location まさかのnil。linenoが取れない。。
  • blocks[1].blocks[2].blocks[1].blocks  配列 レベル2のリストが入ってる。あくまでもリストが入ってる。リストアイテムではない
$Document {
  '$$id': 490,
  document: [Circular],
  context: 'document',
  node_name: 'document',
  attributes: 
   $Hash {
     '$$smap': 
      { sectids: '',
        notitle: '',
        'toc-placement': 'auto',
        stylesheet: '',
        webfonts: '',
        prewrap: '',
        'attribute-undefined': 'drop-line',
        'attribute-missing': 'skip',
        'iconfont-remote': '',
        'caution-caption': 'Caution',
        'important-caption': 'Important',
        'note-caption': 'Note',
        'tip-caption': 'Tip',
        'warning-caption': 'Warning',
        'appendix-caption': 'Appendix',
        'example-caption': 'Example',
        'figure-caption': 'Figure',
        'table-caption': 'Table',
        'toc-title': 'Table of Contents',
        'manname-title': 'NAME',
        'untitled-label': 'Untitled',
        'version-label': 'Version',
        'last-update-label': 'Last updated',
        docfile: 'README.2.adoc',
        docdir: '/home/ubuntu/workspace/asciidoctor',
        docname: 'README.2',
        docdate: '2016-12-27',
        doctime: '16:15:07 UTC',
        docdatetime: '2016-12-27 16:15:07 UTC',
        asciidoctor: '',
        'asciidoctor-version': '1.5.5',
        'safe-mode-name': 'unsafe',
        'safe-mode-unsafe': '',
        'safe-mode-level': 0,
        embedded: '',
        'max-include-depth': 64,
        'user-home': '/home/ubuntu',
        backend: 'html5',
        doctype: 'article',
        htmlsyntax: 'html',
        'doctype-article': '',
        'backend-html5-doctype-article': '',
        'backend-html5': '',
        outfilesuffix: '.html',
        filetype: 'html',
        'filetype-html': '',
        basebackend: 'html',
        'basebackend-html': '',
        'basebackend-html-doctype-article': '',
        localdate: '2016-12-29',
        localtime: '16:21:35 UTC',
        localdatetime: '2016-12-29 16:21:35 UTC',
        stylesdir: '.',
        iconsdir: 'images/icons',
        doctitle: 'レベル1' },
     '$$map': {},
     '$$keys': 
      [ 'sectids',
        'notitle',
        'toc-placement',
        'stylesheet',
        'webfonts',
        'prewrap',
        'attribute-undefined',
        'attribute-missing',
        'iconfont-remote',
        'caution-caption',
        'important-caption',
        'note-caption',
        'tip-caption',
        'warning-caption',
        'appendix-caption',
        'example-caption',
        'figure-caption',
        'table-caption',
        'toc-title',
        'manname-title',
        'untitled-label',
        'version-label',
        'last-update-label',
        'docfile',
        'docdir',
        'docname',
        'docdate',
        'doctime',
        'docdatetime',
        'asciidoctor',
        'asciidoctor-version',
        'safe-mode-name',
        'safe-mode-unsafe',
        'safe-mode-level',
        'embedded',
        'max-include-depth',
        'user-home',
        'backend',
        'doctype',
        'htmlsyntax',
        'doctype-article',
        'backend-html5-doctype-article',
        'backend-html5',
        'outfilesuffix',
        'filetype',
        'filetype-html',
        'basebackend',
        'basebackend-html',
        'basebackend-html-doctype-article',
        'localdate',
        'localtime',
        'localdatetime',
        'stylesdir',
        'iconsdir',
        'doctitle' ],
     '$$none': undefined,
     '$$proc': undefined },
  passthroughs: $Hash { '$$smap': {}, '$$map': {}, '$$keys': [] },
  content_model: 'compound',
  subs: [],
  default_subs: NilClass_alloc { '$$id': 4, apply: [Function], call: [Function] },
  blocks: 
   [ $Block {
       '$$id': 526,
       parent: [Circular],
       document: [Circular],
       context: 'preamble',
       node_name: 'preamble',
       attributes: [Object],
       passthroughs: [Object],
       content_model: 'compound',
       subs: [],
       default_subs: [Object],
       blocks: [Object],
       id: [Object],
       title: [Object],
       caption: [Object],
       style: [Object],
       level: 0,
       next_section_index: 0,
       next_section_number: 1,
       source_location: [Object],
       lines: [] },
     $Section {
       '$$id': 538,
       parent: [Circular],
       document: [Circular],
       context: 'section',
       node_name: 'section',
       attributes: [Object],
       passthroughs: [Object],
       content_model: 'compound',
       subs: [],
       default_subs: [Object],
       blocks: [Object],
       id: '__',
       title: 'レベル2',
       caption: [Object],
       style: [Object],
       level: 1,
       next_section_index: 1,
       next_section_number: 1,
       source_location: [Object],
       numbered: false,
       special: false,
       index: 0,
       number: 1,
       sectname: 'sect1',
       subbed_title: 'レベル2' } ],
  id: NilClass_alloc { '$$id': 4, apply: [Function], call: [Function] },
  title: NilClass_alloc { '$$id': 4, apply: [Function], call: [Function] },
  caption: NilClass_alloc { '$$id': 4, apply: [Function], call: [Function] },
  style: NilClass_alloc { '$$id': 4, apply: [Function], call: [Function] },
  level: 0,
  next_section_index: 1,
  next_section_number: 1,
  source_location: NilClass_alloc { '$$id': 4, apply: [Function], call: [Function] },
  parent_document: NilClass_alloc { '$$id': 4, apply: [Function], call: [Function] },
  references: 
   $Hash {
     '$$smap': 
      { ids: [Object],
        footnotes: [],
        links: [],
        images: [],
        indexterms: [],
        includes: [Object] },
     '$$map': {},
     '$$keys': [ 'ids', 'footnotes', 'links', 'images', 'indexterms', 'includes' ] },
  callouts: $Callouts { '$$id': 494, lists: [ [] ], list_index: 1, co_index: 1 },
  attribute_overrides: 
   $Hash {
     '$$smap': 
      { docfile: 'README.2.adoc',
        docdir: '/home/ubuntu/workspace/asciidoctor',
        docname: 'README.2',
        docdate: '2016-12-27',
        doctime: '16:15:07 UTC',
        docdatetime: '2016-12-27 16:15:07 UTC',
        asciidoctor: '',
        'asciidoctor-version': '1.5.5',
        'safe-mode-name': 'unsafe',
        'safe-mode-unsafe': '',
        'safe-mode-level': 0,
        embedded: '',
        'max-include-depth': 64,
        'allow-uri-read': [Object],
        'user-home': '/home/ubuntu',
        'max-attribute-value-size': [Object] },
     '$$map': {},
     '$$keys': 
      [ 'docfile',
        'docdir',
        'docname',
        'docdate',
        'doctime',
        'docdatetime',
        'asciidoctor',
        'asciidoctor-version',
        'safe-mode-name',
        'safe-mode-unsafe',
        'safe-mode-level',
        'embedded',
        'max-include-depth',
        'allow-uri-read',
        'user-home',
        'max-attribute-value-size' ] },
  safe: 0,
  compat_mode: false,
  sourcemap: true,
  converter: 
   $Html5Converter {
     '$$id': 504,
     xml_mode: false,
     void_element_slash: NilClass_alloc { '$$id': 4, apply: [Function], call: [Function] },
     stylesheets: $Stylesheets { '$$id': 474 } },
  extensions: 
   $Registry {
     '$$id': 508,
     groups: $Hash { '$$smap': {}, '$$map': {}, '$$keys': [] },
     docinfo_processor_extensions: NilClass_alloc { '$$id': 4, apply: [Function], call: [Function] },
     include_processor_extensions: NilClass_alloc { '$$id': 4, apply: [Function], call: [Function] },
     postprocessor_extensions: NilClass_alloc { '$$id': 4, apply: [Function], call: [Function] },
     treeprocessor_extensions: NilClass_alloc { '$$id': 4, apply: [Function], call: [Function] },
     preprocessor_extensions: NilClass_alloc { '$$id': 4, apply: [Function], call: [Function] },
     inline_macro_extensions: NilClass_alloc { '$$id': 4, apply: [Function], call: [Function] },
     block_macro_extensions: NilClass_alloc { '$$id': 4, apply: [Function], call: [Function] },
     block_extensions: NilClass_alloc { '$$id': 4, apply: [Function], call: [Function] },
     document: [Circular] },
  parsed: true,
  header: 
   $Section {
     '$$id': 524,
     parent: [Circular],
     document: [Circular],
     context: 'section',
     node_name: 'section',
     attributes: $Hash { '$$smap': {}, '$$map': {}, '$$keys': [] },
     passthroughs: $Hash { '$$smap': {}, '$$map': {}, '$$keys': [] },
     content_model: 'compound',
     subs: [],
     default_subs: NilClass_alloc { '$$id': 4, apply: [Function], call: [Function] },
     blocks: [],
     id: NilClass_alloc { '$$id': 4, apply: [Function], call: [Function] },
     title: 'レベル1',
     caption: NilClass_alloc { '$$id': 4, apply: [Function], call: [Function] },
     style: NilClass_alloc { '$$id': 4, apply: [Function], call: [Function] },
     level: 0,
     next_section_index: 0,
     next_section_number: 1,
     source_location: 
      $Cursor {
        '$$id': 520,
        file: 'README.2.adoc',
        dir: '/home/ubuntu/workspace/asciidoctor',
        path: 'README.2.adoc',
        lineno: 1 },
     numbered: false,
     special: false,
     index: 0,
     number: 1 },
  counters: $Hash { '$$smap': {}, '$$map': {}, '$$keys': [] },
  attributes_modified: 
   $Set {
     '$$id': 498,
     hash: 
      $Hash {
        '$$smap': {},
        '$$map': {},
        '$$keys': [],
        '$$none': [Object],
        '$$proc': [Object] } },
  options: 
   $Hash {
     '$$smap': 
      { sourcemap: true,
        safe: 'unsafe',
        attributes: [Object],
        header_footer: false },
     '$$map': {},
     '$$keys': [ 'sourcemap', 'safe', 'attributes', 'header_footer' ],
     '$$none': undefined,
     '$$proc': undefined },
  docinfo_processor_extensions: $Hash { '$$smap': {}, '$$map': {}, '$$keys': [] },
  base_dir: '/home/ubuntu/workspace/asciidoctor',
  max_attribute_value_size: NilClass_alloc { '$$id': 4, apply: [Function], call: [Function] },
  backend: NilClass_alloc { '$$id': 4, apply: [Function], call: [Function] },
  reader: 
   $PreprocessorReader {
     '$$id': 512,
     document: [Circular],
     file: 'README.2.adoc',
     dir: '/home/ubuntu/workspace/asciidoctor',
     path: 'README.2.adoc',
     lineno: 17,
     lines: [],
     source_lines: 
      [ '= レベル1',
        '',
        'レベル1本文',
        '',
        '== レベル2',
        '',
        'レベル2本文その1',
        '',
        'レベル2本文その2',
        '',
        '=== レベル3',
        '',
        'レベル3本文その1',
        '',
        'レベル3本文その2' ],
     eof: true,
     look_ahead: 0,
     process_lines: true,
     unescape_next_line: false,
     maxdepth: $Hash { '$$smap': [Object], '$$map': {}, '$$keys': [Object] },
     include_stack: [],
     includes: $Set { '$$id': 492, hash: [Object] },
     skipping: false,
     conditional_stack: [],
     include_processor_extensions: NilClass_alloc { '$$id': 4, apply: [Function], call: [Function] } },
  doctype: 'article',
  outfilesuffix: '.html',
  header_attributes: 
   $Hash {
     '$$smap': 
      { sectids: '',
        notitle: '',
        'toc-placement': 'auto',
        stylesheet: '',
        webfonts: '',
        prewrap: '',
        'attribute-undefined': 'drop-line',
        'attribute-missing': 'skip',
        'iconfont-remote': '',
        'caution-caption': 'Caution',
        'important-caption': 'Important',
        'note-caption': 'Note',
        'tip-caption': 'Tip',
        'warning-caption': 'Warning',
        'appendix-caption': 'Appendix',
        'example-caption': 'Example',
        'figure-caption': 'Figure',
        'table-caption': 'Table',
        'toc-title': 'Table of Contents',
        'manname-title': 'NAME',
        'untitled-label': 'Untitled',
        'version-label': 'Version',
        'last-update-label': 'Last updated',
        docfile: 'README.2.adoc',
        docdir: '/home/ubuntu/workspace/asciidoctor',
        docname: 'README.2',
        docdate: '2016-12-27',
        doctime: '16:15:07 UTC',
        docdatetime: '2016-12-27 16:15:07 UTC',
        asciidoctor: '',
        'asciidoctor-version': '1.5.5',
        'safe-mode-name': 'unsafe',
        'safe-mode-unsafe': '',
        'safe-mode-level': 0,
        embedded: '',
        'max-include-depth': 64,
        'user-home': '/home/ubuntu',
        backend: 'html5',
        doctype: 'article',
        htmlsyntax: 'html',
        'doctype-article': '',
        'backend-html5-doctype-article': '',
        'backend-html5': '',
        outfilesuffix: '.html',
        filetype: 'html',
        'filetype-html': '',
        basebackend: 'html',
        'basebackend-html': '',
        'basebackend-html-doctype-article': '',
        localdate: '2016-12-29',
        localtime: '16:21:35 UTC',
        localdatetime: '2016-12-29 16:21:35 UTC',
        stylesdir: '.',
        iconsdir: 'images/icons',
        doctitle: 'レベル1' },
     '$$map': {},
     '$$keys': 
      [ 'sectids',
        'notitle',
        'toc-placement',
        'stylesheet',
        'webfonts',
        'prewrap',
        'attribute-undefined',
        'attribute-missing',
        'iconfont-remote',
        'caution-caption',
        'important-caption',
        'note-caption',
        'tip-caption',
        'warning-caption',
        'appendix-caption',
        'example-caption',
        'figure-caption',
        'table-caption',
        'toc-title',
        'manname-title',
        'untitled-label',
        'version-label',
        'last-update-label',
        'docfile',
        'docdir',
        'docname',
        'docdate',
        'doctime',
        'docdatetime',
        'asciidoctor',
        'asciidoctor-version',
        'safe-mode-name',
        'safe-mode-unsafe',
        'safe-mode-level',
        'embedded',
        'max-include-depth',
        'user-home',
        'backend',
        'doctype',
        'htmlsyntax',
        'doctype-article',
        'backend-html5-doctype-article',
        'backend-html5',
        'outfilesuffix',
        'filetype',
        'filetype-html',
        'basebackend',
        'basebackend-html',
        'basebackend-html-doctype-article',
        'localdate',
        'localtime',
        'localdatetime',
        'stylesdir',
        'iconsdir',
        'doctitle' ],
     '$$none': undefined,
     '$$proc': undefined } }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment