-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmarkdown.js
More file actions
97 lines (93 loc) · 2.49 KB
/
markdown.js
File metadata and controls
97 lines (93 loc) · 2.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
const { textarea, text, script, domReady } = require("@saltcorn/markup/tags");
const iterator = require("markdown-it-for-inline");
const markdownItMermaid = require("markdown-it-mermaid");
const md = require("markdown-it")().use(
iterator,
"nofollow_links",
"link_open",
function (tokens, idx) {
tokens[idx].attrPush(["rel", "nofollow"]);
},
);
const md_mermaid = require("markdown-it")()
.use(iterator, "nofollow_links", "link_open", function (tokens, idx) {
tokens[idx].attrPush(["rel", "nofollow"]);
})
.use(markdownItMermaid.default);
const markdown = {
name: "Markdown",
sql_name: "text",
fieldviews: {
showAll: {
isEdit: false,
configFields: [
{ name: "mermaid", label: "Render mermaid diagrams", type: "Bool" },
],
run: (v, _req, attr) =>
attr?.mermaid
? md_mermaid.render(v || "") +
script(
domReady(
`$(".mermaid:not([data-processed])").each(function(){
const $e = $(this)
$e.attr("mm-src", $e.text())
});
ensure_script_loaded("/static_assets/"+_sc_version_tag+"/mermaid.min.js")`,
),
)
: md.render(v || ""),
},
peek: {
isEdit: false,
run: (v) => text(v && v.length > 10 ? v.substring(0, 10) : v || ""),
},
edit: {
isEdit: true,
run: (nm, v, attrs, cls) =>
textarea(
{
class: ["form-control", cls],
name: text(nm),
id: `input${text(nm)}`,
rows: 10,
},
text(v) || "",
),
},
},
read: (v) => {
switch (typeof v) {
case "string":
return v;
default:
return undefined;
}
},
};
const render_markdown = {
type: "String",
handlesTextStyle: true,
configFields: [
{ name: "mermaid", label: "Render mermaid diagrams", type: "Bool" },
],
run: (v, _req, attr) =>
attr?.mermaid
? md_mermaid.render(v || "") +
script(
domReady(
`$(".mermaid:not([data-processed])").each(function(){
const $e = $(this)
$e.attr("mm-src", $e.text())
})
ensure_script_loaded("/static_assets/"+_sc_version_tag+"/mermaid.min.js")`,
),
)
: md.render(v || ""),
};
module.exports = {
sc_plugin_api_version: 1,
types: [markdown],
fieldviews: { render_markdown },
functions: { md_to_html: (m) => md.render(m || "") },
ready_for_mobile: true,
};