html: Add markdown render flag option (#616)
New "flags" option in the [markdown] section to customize Misaka's Markdown HTML rendering. By default, no flags are set. ``` [markup] flags = skip-html, escape, hard-wrap ``` Update CHANGES.rst and add the section to the sample isso.conf and isso-dev.conf
This commit is contained in:
parent
2a4e8c231e
commit
86b65f817e
@ -4,6 +4,14 @@ Changelog for Isso
|
|||||||
0.12.3 (UNRELEASED)
|
0.12.3 (UNRELEASED)
|
||||||
-------------------
|
-------------------
|
||||||
|
|
||||||
|
- New "flags" option in the [markdown] section to customize Misaka's Markdown
|
||||||
|
HTML rendering. By default, no flags are set.
|
||||||
|
|
||||||
|
[markup]
|
||||||
|
flags = skip-html, escape, hard-wrap
|
||||||
|
|
||||||
|
Check docs/configuration/server.rst for more details.
|
||||||
|
|
||||||
0.12.2 (2019-01-21)
|
0.12.2 (2019-01-21)
|
||||||
-------------------
|
-------------------
|
||||||
|
|
||||||
|
@ -298,12 +298,20 @@ supported, but new languages are relatively easy to add.
|
|||||||
|
|
||||||
[markup]
|
[markup]
|
||||||
options = strikethrough, superscript, autolink
|
options = strikethrough, superscript, autolink
|
||||||
|
flags = skip-html, escape, hard-wrap
|
||||||
allowed-elements =
|
allowed-elements =
|
||||||
allowed-attributes =
|
allowed-attributes =
|
||||||
|
|
||||||
options
|
options
|
||||||
`Misaka-specific Markdown extensions <http://misaka.61924.nl/#api>`_, all
|
`Misaka-specific Markdown extensions <https://misaka.61924.nl/#api>`_, all
|
||||||
flags starting with `EXT_` can be used there, separated by comma.
|
extension flags can be used there, separated by comma, either by their name
|
||||||
|
or as `EXT_`_.
|
||||||
|
|
||||||
|
flags
|
||||||
|
`Misaka-specific HTML rendering flags
|
||||||
|
<https://misaka.61924.nl/#html-render-flags>`_, all html rendering flags
|
||||||
|
can be used here, separated by comma, either by their name or as `HTML_`_.
|
||||||
|
Per Misaka's defaults, no flags are set.
|
||||||
|
|
||||||
allowed-elements
|
allowed-elements
|
||||||
Additional HTML tags to allow in the generated output, comma-separated. By
|
Additional HTML tags to allow in the generated output, comma-separated. By
|
||||||
|
@ -89,6 +89,7 @@ class TestHTML(unittest.TestCase):
|
|||||||
conf = config.new({
|
conf = config.new({
|
||||||
"markup": {
|
"markup": {
|
||||||
"options": "autolink",
|
"options": "autolink",
|
||||||
|
"flags": "",
|
||||||
"allowed-elements": "",
|
"allowed-elements": "",
|
||||||
"allowed-attributes": ""
|
"allowed-attributes": ""
|
||||||
}
|
}
|
||||||
|
@ -5,6 +5,11 @@ from __future__ import unicode_literals
|
|||||||
import bleach
|
import bleach
|
||||||
import misaka
|
import misaka
|
||||||
|
|
||||||
|
try:
|
||||||
|
from backports.configparser import NoOptionError
|
||||||
|
except ImportError:
|
||||||
|
from configparser import NoOptionError
|
||||||
|
|
||||||
|
|
||||||
class Sanitizer(object):
|
class Sanitizer(object):
|
||||||
|
|
||||||
@ -49,9 +54,9 @@ class Sanitizer(object):
|
|||||||
|
|
||||||
|
|
||||||
def Markdown(extensions=("strikethrough", "superscript", "autolink",
|
def Markdown(extensions=("strikethrough", "superscript", "autolink",
|
||||||
"fenced-code")):
|
"fenced-code"), flags=[]):
|
||||||
|
|
||||||
renderer = Unofficial()
|
renderer = Unofficial(flags=flags)
|
||||||
md = misaka.Markdown(renderer, extensions=extensions)
|
md = misaka.Markdown(renderer, extensions=extensions)
|
||||||
|
|
||||||
def inner(text):
|
def inner(text):
|
||||||
@ -80,7 +85,11 @@ class Markup(object):
|
|||||||
|
|
||||||
def __init__(self, conf):
|
def __init__(self, conf):
|
||||||
|
|
||||||
parser = Markdown(conf.getlist("options"))
|
try:
|
||||||
|
conf_flags = conf.getlist("flags")
|
||||||
|
except NoOptionError:
|
||||||
|
conf_flags = []
|
||||||
|
parser = Markdown(extensions=conf.getlist("options"), flags=conf_flags)
|
||||||
sanitizer = Sanitizer(
|
sanitizer = Sanitizer(
|
||||||
conf.getlist("allowed-elements"),
|
conf.getlist("allowed-elements"),
|
||||||
conf.getlist("allowed-attributes"))
|
conf.getlist("allowed-attributes"))
|
||||||
|
@ -28,6 +28,7 @@ enabled = false
|
|||||||
|
|
||||||
[markup]
|
[markup]
|
||||||
options = strikethrough, autolink, fenced_code, no_intra_emphasis
|
options = strikethrough, autolink, fenced_code, no_intra_emphasis
|
||||||
|
flags =
|
||||||
allowed-elements =
|
allowed-elements =
|
||||||
allowed-attributes =
|
allowed-attributes =
|
||||||
|
|
||||||
|
@ -185,6 +185,11 @@ require-email = false
|
|||||||
# there, separated by comma.
|
# there, separated by comma.
|
||||||
options = strikethrough, autolink, fenced_code, no_intra_emphasis
|
options = strikethrough, autolink, fenced_code, no_intra_emphasis
|
||||||
|
|
||||||
|
# Misaka-specific HTML rendering flags, all html rendering flags can be used
|
||||||
|
# here, separated by comma, either by their name or as HTML_<flag>.
|
||||||
|
# Per Misaka's defaults, no flags are set.
|
||||||
|
flags =
|
||||||
|
|
||||||
# Additional HTML tags to allow in the generated output, comma-separated. By
|
# Additional HTML tags to allow in the generated output, comma-separated. By
|
||||||
# default, only a, blockquote, br, code, del, em, h1, h2, h3, h4, h5, h6, hr,
|
# default, only a, blockquote, br, code, del, em, h1, h2, h3, h4, h5, h6, hr,
|
||||||
# ins, li, ol, p, pre, strong, table, tbody, td, th, thead and ul are allowed.
|
# ins, li, ol, p, pre, strong, table, tbody, td, th, thead and ul are allowed.
|
||||||
|
Loading…
Reference in New Issue
Block a user