git.iko.soy/typeable/pandoc
on master help sign in
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].

commitb75d8de679f57c6eb8bdedfc429509708cd97a4a authorJohn MacFarlane <jgm@berkeley.edu> dateSun 26 Apr 2020, 15:39 (6 years ago) parent024cca7
3 files changed+34−8
MANUAL.txt+31 src/Text/Pandoc/Extensions.hs+2−4 src/Text/Pandoc/Readers/CommonMark.hs+1−4
MANUAL.txt+31
@@ -4933,6 +4933,37 @@ in pandoc, but may be enabled by adding `+EXTENSION` to the format
49334933name, where `EXTENSION` is the name of the extension. Thus, for
49344934example, `markdown+hard_line_breaks` is Markdown with hard line breaks.
49354935
4936+#### Extension: `attributes` ####
4937+
4938+Allows attributes to be attached to any inline or block-level
4939+element. The syntax for the attributes is the same as that
4940+used in [`header_attributes`][Extension: `header_attributes`].
4941+
4942+- Attributes that occur immediately after an inline
4943+ element affect that element. If they follow a space, then they
4944+ belong to the space. (Hence, this option subsumes
4945+ `inline_code_attributes` and `link_attributes`.)
4946+- Attributes that occur immediately before a block
4947+ element, on a line by themselves, affect that
4948+ element.
4949+- Consecutive attribute specifiers may be used,
4950+ either for blocks or for inlines. Their attributes
4951+ will be combined.
4952+- Attributes that occur at the end of the text of
4953+ a Setext or ATX heading (separated by whitespace
4954+ from the text) affect the heading element. (Hence, this
4955+ option subsumes `header_attributes`.)
4956+- Attributes that occur after the opening fence
4957+ in a fenced code block affect the code block element. (Hence,
4958+ this option subsumes `fenced_code_attributes`.)
4959+- Attributes that occur at the end of a reference
4960+ link definition affect links that refer to that
4961+ definition.
4962+
4963+Note that pandoc's AST does not currently allow attributes
4964+to be attached to arbitrary elements. Hence a Span or Div
4965+container will be added if needed.
4966+
49364967#### Extension: `old_dashes` ####
49374968
49384969Selects the pandoc <= 1.8.2.1 behavior for parsing smart dashes:
src/Text/Pandoc/Extensions.hs+2−4
@@ -150,6 +150,7 @@ data Extension =
150150 | Ext_tex_math_single_backslash -- ^ TeX math btw \(..\) \[..\]
151151 | Ext_yaml_metadata_block -- ^ YAML metadata block
152152 | Ext_gutenberg -- ^ Use Project Gutenberg conventions for plain
153+ | Ext_attributes -- ^ Generic attribute syntax
153154 deriving (Show, Read, Enum, Eq, Ord, Bounded, Data, Typeable, Generic)
154155
155156-- | Extensions to be used with pandoc-flavored markdown.
@@ -447,11 +448,8 @@ getAllExtensions f = universalExtensions <> getAll f
447448 , Ext_fenced_divs
448449 , Ext_bracketed_spans
449450 , Ext_raw_attribute
450− , Ext_inline_code_attributes
451− , Ext_fenced_code_attributes
452− , Ext_link_attributes
453− , Ext_header_attributes
454451 , Ext_implicit_header_references
452+ , Ext_attributes
455453 ]
456454 getAll "commonmark" = getAll "gfm"
457455 getAll "org" = autoIdExtensions <>
src/Text/Pandoc/Readers/CommonMark.hs+1−4
@@ -48,10 +48,7 @@ readCommonMark opts s = do
4848 [ fencedDivSpec | isEnabled Ext_fenced_divs opts ] ++
4949 [ bracketedSpanSpec | isEnabled Ext_bracketed_spans opts ] ++
5050 [ rawAttributeSpec | isEnabled Ext_raw_attribute opts ] ++
51− [ attributesSpec | isEnabled Ext_link_attributes opts ||
52− isEnabled Ext_inline_code_attributes opts ||
53− isEnabled Ext_fenced_code_attributes opts ||
54− isEnabled Ext_header_attributes opts ] ++
51+ [ attributesSpec | isEnabled Ext_attributes opts ] ++
5552 [ pipeTableSpec | isEnabled Ext_pipe_tables opts ] ++
5653 [ autolinkSpec | isEnabled Ext_autolink_bare_uris opts ] ++
5754 [ emojiSpec | isEnabled Ext_emoji opts ] ++