-
Notifications
You must be signed in to change notification settings - Fork 26
Expand file tree
/
Copy pathmarkdown-web.htm
More file actions
178 lines (154 loc) · 8.17 KB
/
markdown-web.htm
File metadata and controls
178 lines (154 loc) · 8.17 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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>DataFormsJS Markdown using Web Component</title>
<link rel="stylesheet" href="https://d2xbd92kui7v97.cloudfront.net/site/css/getting-started.css">
<link rel="stylesheet" href="css/markdown.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/highlightjs/cdn-release@10.1.2/build/styles/atom-one-dark.min.css">
</head>
<body>
<header>
<nav is="spa-links">
<a href="#/">Home</a>
<a href="#/local">Local Content</a>
<a href="#/data">Markdown using Data Binding</a>
<a href="#/404-content">Markdown Fetch Error</a>
</nav>
</header>
<main id="view"></main>
<template id="loading-screen">
<div>Loading...</div>
</template>
<url-router view-selector="#view">
<url-route path="/" onload="showSelectedLibrary()">
<template>
<h1>DataFormsJS <markdown-content> Web Component<br> with [<span id="selected-library"></span>] Markdown Library</h1>
<!--
To display markdown from a web service or site only [url] needs to be included:
<markdown-content url="..."></markdown-content>
The example below shows additional options to show a loading screen while
content is being fetched and to update links after the markdown has been rendered.
These attributes make it easy to show content that links to other sites correctly
and for the current page not to be changed when the user clicks a link.
By default if [link-root-url] is not used the local links would update based
on the path of the main [url] attribute.
-->
<markdown-content
url="https://raw.githubusercontent.com/dataformsjs/dataformsjs/master/README.md"
load-only-once
loading-selector="#loading-screen"
link-target="_blank"
link-rel="noopener"
link-root-url="https://github.com/dataformsjs/dataformsjs/blob/master/">
</markdown-content>
</template>
</url-route>
<url-route path="/local">
<template>
<section class="description">
<p>By default unless [use-root-url="false"] is used content that points to relative URL's will automatically be handled based on the path of the Markdown Document.</p>
<p><a href="https://github.com/mark-anders/relative-image-url" target="_blank" rel="noopener">https://github.com/mark-anders/relative-image-url</a></p>
</section>
<!--
To see an image error add:
use-root-url="false"
-->
<markdown-content
url="https://raw.githubusercontent.com/mark-anders/relative-image-url/master/README.md"
load-only-once
loading-selector="#loading-screen">
</markdown-content>
</template>
</url-route>
<url-route path="/data" lazy-load="json_data, data_list">
<template>
<json-data
url="https://www.dataformsjs.com/data/random/markdown">
<is-loading>
<span class="loading">Loading...</span>
</is-loading>
<has-error>
<span class="error" data-bind="errorMessage"></span>
</has-error>
<is-loaded>
<markdown-content data-bind="content"></markdown-content>
<data-list data-bind="list" template-selector="#md-items"></data-list>
<template id="md-items">
<markdown-content>
<script type="text/markdown">${content}</script>
</markdown-content>
</template>
</is-loaded>
</json-data>
</template>
</url-route>
<url-route path="/404-content">
<template>
<markdown-content url="/404"></markdown-content>
</template>
</url-route>
</url-router>
<!--
DataFormsJS Web Components
https://www.dataformsjs.com
-->
<script type="module" src="https://cdn.jsdelivr.net/npm/dataformsjs@5/js/web-components/url-router.min.js"></script>
<script type="module" src="https://cdn.jsdelivr.net/npm/dataformsjs@5/js/web-components/spa-links.min.js"></script>
<script type="module" src="https://cdn.jsdelivr.net/npm/dataformsjs@5/js/web-components/markdown-content.min.js"></script>
<script nomodule src="https://cdn.jsdelivr.net/npm/dataformsjs@5/js/web-components/polyfill.min.js"></script>
<!--
[marked] requires `trimRight` for IE
-->
<script nomodule src="https://cdn.jsdelivr.net/npm/dataformsjs@5/js/scripts/polyfills.min.js"></script>
<script>
window.lazyLoad = {
json_data: { module: 'https://cdn.jsdelivr.net/npm/dataformsjs@5/js/web-components/json-data.min.js' },
data_list: { module: 'https://cdn.jsdelivr.net/npm/dataformsjs@5/js/web-components/data-list.min.js' },
};
function showSelectedLibrary() {
var library = 'None';
if (window.marked) {
library = 'marked';
} else if (window.markdownit) {
library = 'markdown-it';
} else if (window.remarkable) {
library = 'Remarkable';
}
document.getElementById('selected-library').textContent = library;
}
</script>
<!--
Pick a Markdown Library:
https://marked.js.org/
https://markdown-it.github.io/
https://github.com/jonschlinkert/remarkable
Optional:
https://highlightjs.org/
https://github.com/cure53/DOMPurify
https://github.com/markdown-it/markdown-it-emoji
CSS for highlight.js is at the top of this file
-->
<script src="https://cdn.jsdelivr.net/npm/marked@3.0.8/lib/marked.min.js"></script>
<!-- <script src="https://cdn.jsdelivr.net/npm/marked@4.0.1/marked.min.js"></script> -->
<!-- <script src="https://cdn.jsdelivr.net/npm/markdown-it@12.0.2/dist/markdown-it.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/markdown-it-emoji@2.0.0/dist/markdown-it-emoji.min.js"></script> -->
<!-- <script src="https://cdn.jsdelivr.net/npm/remarkable@2.0.1/dist/remarkable.min.js"></script> -->
<script src="https://cdn.jsdelivr.net/gh/highlightjs/cdn-release@10.1.2/build/highlight.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/dompurify@2.2.2/dist/purify.min.js"></script>
<!--
API that allows apps to handle <markdown-content> after the content has rendered.
-->
<script>
'use strict';
document.addEventListener('app:markdownRendered', function(e) {
// The event 'app:markdownRendered' gets called once markdown is rendered or after an
// error from fetch. Uncomment code below to see how it works.
// console.log(e.target);
// const html = e.target.innerHTML;
// console.log('Rendered <markdown-content> [' + html.substring(0, 20) + '...] - Total Length: ' + html.length);
});
</script>
</body>
</html>