您需要先安装一个扩展,例如 篡改猴、Greasemonkey 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 Userscripts ,之后才能安装此脚本。
您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。
您需要先安装用户脚本管理器扩展后才能安装此脚本。
Checks PRE and CODE tags in Summernote and ensures that their contents use HTML entities for proper display.
Important: Versions 1 to 2 should be considered experimental and may lead to data loss. Back up your entries before saving (this backup script can help with that).
This script checks PRE and CODE tags in the Summernote editor when it loads and ensures that any HTML tags they contain are written with HTML entities for proper display, mainly by replacing < and > characters. The clearest way to explain why this is useful is probably to explain why showing HTML tags in Kanka entries is difficult in the first place:
<pre><p>text</p></pre>
results in the paragraph being rendered outside the PRE block instead of shown inside it as markup; and if you try to show just an opening tag like <code><span></code>
, it gets replaced with <code><span></span></code>
because the validator wants all tags to be closed, which doesn’t display anything on the rendered page).<
for <
and >
for >
, e.g. <code><span></code>
. When the page is rendered, these are resolved to their respective characters, so you get what you want. But...Hence, this script solves part 3 of the issue by undoing Summernote’s conversion of HTML entities inside PRE and CODE tags specifically. It does not validate HTML before saving, so you are still responsible for using HTML entities in the first place. Various HTML entity converters on the Web can help make that step easier.
If you write CSS or programming language code in PRE or CODE tags, note that the <
and >
comparison operators (or CSS child selector, in the latter’s case) will be excluded from replacement as long as they are surrounded by spaces, so you can still display them properly. If you run into other characters that should not be converted to HTML entities, please let me know.