Debian Codegraph @

docs/src/markdown/extensions/striphtml.md

raw
1 ---
2 icon: lucide/eraser
3 ---
4 [:octicons-file-code-24:][_striphtml]{: .source-link }
5
6 # StripHTML
7
8 ## Overview
9
10 StripHTML (formally known as PlainHTML) is a simple extension that is run at the end of post-processing. It searches
11 the final output stripping out unwanted comments and/or tag attributes. Though it does its best to be loaded at the very
12 end of the process, it helps to include this one last when loading up your extensions.
13
14 ```text title="Stripping Comments"
15 <!-- We are only allowing strip_comments and strip_js_on_attributes
16 in this example. -->
17
18 Here is a <strong onclick="myFunction();">test</strong>.
19 ```
20
21 /// html | div.result
22 ```html
23 <p>Here is a <strong>test</strong>.</p>
24 ```
25 ///
26
27 Because comments aren't stripped until the end in a post-processing step, they are present throughout the entire
28 Markdown conversion process and could possibly affect parsing, so be careful how you generally insert comments.
29
30 /// warning
31 This is not meant to be a sanitizer for HTML. This is just meant to try and strip out style, script, classes, etc.
32 to provide a plain HTML output for the times this is desired; this is not meant as a security extension. If you
33 want something to secure the output, you should consider running a sanitizer like [Bleach][bleach].
34 ///
35
36 The StripHTML extension can be included in Python Markdown by using the following:
37
38 ```py3
39 import markdown
40 md = markdown.Markdown(extensions=['pymdownx.striphtml'])
41 ```
42
43 ## Options
44
45 By default, StripHTML only strips attributes starting with `on` (for instance `onclick`). StripHTML also strips
46 HTML comments. If desired, its behavior can be configured to strip less or even more, but it is limited to attributes
47 and comments.
48
49 Option | Type | Default | Description
50 ------------------------ |--------- | ------------ | -----------
51 `strip_comments` | bool | `#!py3 True` | Strip HTML comments during post process.
52 `strip_js_on_attributes` | bool | `#!py3 True` | Strip JavaScript script attributes with the pattern on* during post process.
53 `strip_attributes` | [string] | `#!py3 []` | A list of tag attribute names to strip.