Lib shared by markdown and filters for manipulating attributes in an internally-used vocabulary for tunneling markdown meta attributes to later stages via standard SAX events.

The vocabulary for doing this contain the attributes markdown:roundtrip and markdown:prunable) and is used to

  • tunnel fallback content for forward-referenced links which never get declared later (ie. tunnel original input character data received by markdown to Tokenizer such that on unresolved entities, when roundtrip content is present, that content will be output)
  • prevent filtering <p> tags from list items which only consist of a single paragraph when the paragraph markup came from verbatim input HTML (whereas markdown-generated single <p>s get collapsed into their containers)

Implementation quirks:

  • in the latter case both markdown:prunable and markdown:roundtrip are used (markdown:rountrip is misused/set to "true" even though the string "true" isn't from input: in markdown.awkjs, a generated element (= not from verbatim tags in input) is always marked with markdown:roundtrip="true"`; see note below about a failed attempt to refactor this
  • markdown:roundtrip can be set to any string (such as "false") which doesn't change behaviour; code only checks for existance of the markdown:rountrip attribute
  • note this was once considered a start for full markdown/HTML roundtripping (ie. have generated HTML contain attributes which can be used to recover exact input markdown) but this never came to be, hence the naming.

Member Details

add_markdown_roundtrip_content(buffer, attr_content): string static

Appends (blindly) supplied string as value of the markdown:roundtrip attribute to a buffer. Note this doesn't check or replace preexisting attribute specifications in the buffer.

Parameters

Name Type Description
buffer string

string to append attribute specification to

attr_content string

attribute value to append; note this must be attribute-encoded for syntactically valid serialization into a double-quoted attribute specification

Returns

string

buffer with markdown:roundtrip="<value of attr_content>" appended, with leading blank if buffer isn't empty

get_roundtrip_content(attrs): string static

Returns, from the supplied attribute specification string, the value of the markdown:roundtrip attribute used by markdown.awkjs to store source markdown text content on markdown-generated HTML elements. Currently, markdown.awkjs makes use of this only on anchors generated from forward links, and for controlling internal empty elements pruning.

Parameters

Name Type Description
attrs string

Returns

string
has_non_markdown_attributes(attrs): string static

Returns (whether the supplied string has) attributes other than those prefixed by markdown:.

Parameters

Name Type Description
attrs string

Returns

string
is_prunable(attrs, attrs_array): string static

Returns (as empty/non-empty string encoding of a boolean value) whether the supplied attribute string contains only attributes in the markdown vocabulary (indicating that an element is ok to prune since it doesn't origin from inline/block HTML nor has prunable="false").

Used for pruning empty paragraphs and handle "forced" paragraphs in list items (ie. separated with blank lines from preceding list items).

Parameters

Name Type Description
attrs string

input attributes as string serialization

attrs_array Object.<string, string>=

map of input attributes

Returns

string
set_nonprunable(attrs): string static

Returns an attribute string serialization which has all input attributes (of the input serialization), plus prunable="false" by string concatenation.

Parameters

Name Type Description
attrs string

Returns

string
strip_markdown_vocabulary(attrs, attrs_array): string static

Returns the input string (an HTML/XML attribute string) stripped from markdown-internal attributes, if it has any. This will return the input string unchanged if it hasn't markdown vocab, so can be used to roundtrip inline/block HTML/XML content verbatim; but if it has markdown vocab, it will synthesize a new attribute string. In the latter case the order, character positions and quotedness of attribute specifications aren't preserved.

Parameters

Name Type Description
attrs null | string

string containing attribute specification(s) ie. a string serialization of attrs_array

attrs_array Object.<string, string>

hashmap mapping attribute names to values

Returns

string

attribute serialization of all attributes of attrs/attrs_array, without those belonging to the markdown vocabulary