Skip to content

Commit

Permalink
Add "class" option to "raw" directive.
Browse files Browse the repository at this point in the history
Classe values may already be specified via a preceding
"class" directive. This commit provides the concise alternative
known from other directives.

git-svn-id: https://svn.code.sf.net/p/docutils/code/trunk/docutils@8821 929543f6-e4f2-0310-98a6-ba3bd3dd1d04
  • Loading branch information
Günter Milde committed Sep 11, 2021
1 parent 2958485 commit a4cb4ae
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
2 changes: 2 additions & 0 deletions HISTORY.txt
Expand Up @@ -40,6 +40,8 @@ Changes Since 0.17.1
- `Meta` directive class (moved from html.py) inserts `meta`
(instead of `pending`) nodes.

- Add `class` option to `Raw` directive.

* docutils/tools/math/math2html.py,
docutils/tools/math/tex2unicode.py,
docutils/writers/html5/math.css
Expand Down
5 changes: 4 additions & 1 deletion docs/ref/rst/directives.txt
Expand Up @@ -1484,7 +1484,7 @@ Raw Data Pass-Through
:Directive Type: "raw"
:Doctree Element: raw_
:Directive Arguments: One or more, required (output format types).
:Directive Options: Possible.
:Directive Options: Possible (see below).
:Directive Content: Stored verbatim, uninterpreted. None (empty) if a
"file" or "url" option given.
:Configuration Setting: raw_enabled_
Expand Down Expand Up @@ -1554,6 +1554,9 @@ The following options are recognized:
The text encoding of the external raw data (file or URL).
Defaults to the document's encoding (if specified).

and the common option `:class:`_.


.. _"raw" role: roles.html#raw


Expand Down
6 changes: 4 additions & 2 deletions docutils/parsers/rst/directives/misc.py
Expand Up @@ -216,7 +216,8 @@ class Raw(Directive):
final_argument_whitespace = True
option_spec = {'file': directives.path,
'url': directives.uri,
'encoding': directives.encoding}
'encoding': directives.encoding,
'class': directives.class_option}
has_content = True

def run(self):
Expand Down Expand Up @@ -288,7 +289,8 @@ def run(self):
else:
# This will always fail because there is no content.
self.assert_has_content()
raw_node = nodes.raw('', text, **attributes)
raw_node = nodes.raw('', text, classes=self.options.get('class', []),
**attributes)
(raw_node.source,
raw_node.line) = self.state_machine.get_source_and_line(self.lineno)
return [raw_node]
Expand Down

0 comments on commit a4cb4ae

Please sign in to comment.