-
Notifications
You must be signed in to change notification settings - Fork 4
/
index.html
134 lines (115 loc) · 4.91 KB
/
index.html
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
<!doctype html>
<html lang="en" class="govuk-template">
<head>
<meta charset="utf-8">
<title>paste-html-to-govspeak</title>
<link href="govuk-frontend-2.7.0.min.css" rel="stylesheet">
<style>
pre {
min-height: 100px;
max-height: 500px;
overflow-y: scroll;
border: 1px solid black;
white-space: pre-wrap;
}
#paste-formatted-html-input {
white-space: pre;
}
</style>
</head>
<body class="govuk-template__body">
<div class="govuk-width-container">
<main class="govuk-main-wrapper">
<h1 class="govuk-heading-xl">paste-html-to-govspeak</h1>
<p class="govuk-body">
A tool that converts pastes HTML into
<a href="https://github.com/alphagov/govspeak" target="_blank">govspeak</a>.
For more information check the
<a href="https://github.com/alphagov/paste-html-to-govspeak#readme" target="_blank">repo</a>.
</p>
<h2 class="govuk-heading-l">Paste Demo</h2>
<p class="govuk-body">
To test, paste rich text content into the form below.
</p>
<textarea class="govuk-textarea" rows="10" id="paste-textarea"></textarea>
<details class="govuk-details">
<summary class="govuk-details__summary">
<span class="govuk-details__summary-text">
Debug information from last paste
</span>
</summary>
<div class="govuk-details__text">
<h3 class="govuk-heading-m">Raw HTML Input</h3>
<pre id="paste-raw-html-input"></pre>
<h3 class="govuk-heading-m">Formatted HTML Input</h3>
<pre id="paste-formatted-html-input"></pre>
<h3 class="govuk-heading-m">Text Input</h3>
<pre id="paste-text-input"></pre>
<h3 class="govuk-heading-m">Govspeak</h3>
<pre id="paste-govspeak"></pre>
</div>
</details>
<hr />
<h2 class="govuk-heading-l" id="html-to-govspeak">HTML To Govspeak</h2>
<p class="govuk-body">
Enter HTML content into the form below for govspeak output
</p>
<textarea class="govuk-textarea" rows="10" id="html-textarea"></textarea>
<h2 class="govuk-heading-m">Govspeak</h2>
<pre id="html-govspeak"></pre>
<script src="dist/paste-html-to-markdown.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/js-beautify/1.9.0/beautify-html.js"></script>
<script>
var pasteTextarea = document.getElementById('paste-textarea')
var pasteRawHtmlInputElement = document.getElementById('paste-raw-html-input')
var pasteFormattedHtmlInputElement = document.getElementById('paste-formatted-html-input')
var pasteTextInputElement = document.getElementById('paste-text-input')
var pasteGovspeakElement = document.getElementById('paste-govspeak')
var htmlTextarea = document.getElementById('html-textarea')
pasteTextarea.addEventListener('paste', function () {
pasteGovspeakElement.textContent = ''
})
pasteTextarea.addEventListener('paste', window.pasteHtmlToGovspeak.pasteListener)
pasteTextarea.addEventListener('htmlpaste', function (e) {
if (e.detail) {
pasteRawHtmlInputElement.textContent = e.detail
try {
pasteFormattedHtmlInputElement.textContent = prettyHtml(e.detail)
} catch (err) {
console.error('Failed to make the HTML pretty: ' + err.message)
pasteFormattedHtmlInputElement.textContent = 'HTML failed to be formatted'
}
} else {
pasteRawHtmlInputElement.textContent = 'HTML was not pasted'
pasteFormattedHtmlInputElement.textContent = 'HTML was not pasted'
}
})
pasteTextarea.addEventListener('textpaste', function (e) {
if (e.detail) {
pasteTextInputElement.textContent = e.detail
} else {
pasteTextInputElement.textContent = 'Text was not pasted'
}
})
pasteTextarea.addEventListener('govspeak', function (e) {
pasteGovspeakElement.textContent = e.detail
})
function htmlToGovspeakListener () {
var govspeak = window.pasteHtmlToGovspeak.htmlToGovspeak(htmlTextarea.value)
document.getElementById('html-govspeak').textContent = govspeak
}
htmlTextarea.addEventListener('input', htmlToGovspeakListener)
// convert any initial value
htmlToGovspeakListener()
function prettyHtml (html) {
return window.html_beautify(html, {
indent_size: 2,
wrap_line_length: 160,
wrap_attributes: 'force-expand-multiline'
})
}
</script>
</main>
</div>
</body>
</html>