Greasy Fork 还支持 简体中文。

Kanka Preserve HTML Entities in Summernote

Checks PRE and CODE tags in Summernote and ensures that their contents use HTML entities for proper display.

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         Kanka Preserve HTML Entities in Summernote
// @namespace    http://tampermonkey.net/
// @version      2
// @description  Checks PRE and CODE tags in Summernote and ensures that their contents use HTML entities for proper display.
// @author       Salvatos
// @license      MIT
// @match        https://kanka.io/*
// @match        https://marketplace.kanka.io/*
// @icon         https://www.google.com/s2/favicons?domain=kanka.io
// @run-at       document-end
// ==/UserScript==

// Wait for Summernote to initialize
$('#entry').on('summernote.init', function() {
    // Grab node tree from visual editor
    var masterNode = document.querySelector('#entry + .note-editor .note-editable');

    // Find CODEs and PREs
    masterNode.querySelectorAll(":is(pre, code)").forEach((domObject) => {
        domObject.replaceChildren(domObject.innerHTML);
        // Exclude ' < '  and ' > ' for CSS and comparison operators
        domObject.textContent = domObject.textContent.replace(/ &lt; /g, " < ").replace(/ &gt; /g, " > ");
    });

    // Apply changes to master copy in case of immediate save or switch to code view
    document.getElementById('entry').value = masterNode.innerHTML;
    // BUG: for some reason, this causes changes made in code view to be discarded if you don’t switch back to visual first, so let’s bring back our good old code view save fix...
    $('#entry').on('summernote.change.codeview', function(we, contents, $editable) {
        $(this).val(contents);
    });
});