Add generic attributes extension.

This allows attributes to be added to any block or inline
element, in principle.  (Though in many cases this will be
done by adding a Div or Span container, since pandoc's
AST doesn't have a slot for attributes for most elements.)

Currently this is only possible with the commonmark and gfm
readers.

Add `Ext_attributes` constructor for `Extension` [API change].
This commit is contained in:
John MacFarlane 2020-04-26 15:39:49 -07:00
parent 0db4702042
commit 8d523d80d4
3 changed files with 34 additions and 8 deletions

View file

@ -4933,6 +4933,37 @@ in pandoc, but may be enabled by adding `+EXTENSION` to the format
name, where `EXTENSION` is the name of the extension. Thus, for
example, `markdown+hard_line_breaks` is Markdown with hard line breaks.
#### Extension: `attributes` ####
Allows attributes to be attached to any inline or block-level
element. The syntax for the attributes is the same as that
used in [`header_attributes`][Extension: `header_attributes`].
- Attributes that occur immediately after an inline
element affect that element. If they follow a space, then they
belong to the space. (Hence, this option subsumes
`inline_code_attributes` and `link_attributes`.)
- Attributes that occur immediately before a block
element, on a line by themselves, affect that
element.
- Consecutive attribute specifiers may be used,
either for blocks or for inlines. Their attributes
will be combined.
- Attributes that occur at the end of the text of
a Setext or ATX heading (separated by whitespace
from the text) affect the heading element. (Hence, this
option subsumes `header_attributes`.)
- Attributes that occur after the opening fence
in a fenced code block affect the code block element. (Hence,
this option subsumes `fenced_code_attributes`.)
- Attributes that occur at the end of a reference
link definition affect links that refer to that
definition.
Note that pandoc's AST does not currently allow attributes
to be attached to arbitrary elements. Hence a Span or Div
container will be added if needed.
#### Extension: `old_dashes` ####
Selects the pandoc <= 1.8.2.1 behavior for parsing smart dashes:

View file

@ -150,6 +150,7 @@ data Extension =
| Ext_tex_math_single_backslash -- ^ TeX math btw \(..\) \[..\]
| Ext_yaml_metadata_block -- ^ YAML metadata block
| Ext_gutenberg -- ^ Use Project Gutenberg conventions for plain
| Ext_attributes -- ^ Generic attribute syntax
deriving (Show, Read, Enum, Eq, Ord, Bounded, Data, Typeable, Generic)
-- | Extensions to be used with pandoc-flavored markdown.
@ -447,11 +448,8 @@ getAllExtensions f = universalExtensions <> getAll f
, Ext_fenced_divs
, Ext_bracketed_spans
, Ext_raw_attribute
, Ext_inline_code_attributes
, Ext_fenced_code_attributes
, Ext_link_attributes
, Ext_header_attributes
, Ext_implicit_header_references
, Ext_attributes
]
getAll "commonmark" = getAll "gfm"
getAll "org" = autoIdExtensions <>

View file

@ -48,10 +48,7 @@ readCommonMark opts s = do
[ fencedDivSpec | isEnabled Ext_fenced_divs opts ] ++
[ bracketedSpanSpec | isEnabled Ext_bracketed_spans opts ] ++
[ rawAttributeSpec | isEnabled Ext_raw_attribute opts ] ++
[ attributesSpec | isEnabled Ext_link_attributes opts ||
isEnabled Ext_inline_code_attributes opts ||
isEnabled Ext_fenced_code_attributes opts ||
isEnabled Ext_header_attributes opts ] ++
[ attributesSpec | isEnabled Ext_attributes opts ] ++
[ pipeTableSpec | isEnabled Ext_pipe_tables opts ] ++
[ autolinkSpec | isEnabled Ext_autolink_bare_uris opts ] ++
[ emojiSpec | isEnabled Ext_emoji opts ] ++