This repository has been archived by the owner on Mar 9, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
TextformatterParsedownExtraPluginConfig.php
309 lines (276 loc) · 13.6 KB
/
TextformatterParsedownExtraPluginConfig.php
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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
<?php
/**
* TextformatterParsedownExtraPlugin
*
* @processwire 2.8+
* @author: Mike Rockett
* @license ISC
*/
class TextformatterParsedownExtraPluginConfig extends ModuleConfig
{
/**
* Get default configuration, automatically passed to input fields.
* @return array
*/
public function getDefaults()
{
return [
'html5ElementSuffix' => true,
'abbreviations' => '',
// 'links' => [], #reserved
'linkAttributes' => '',
'externalLinkAttributes' => '',
'imageAttributes' => '',
'externalImageAttributes' => '',
'codeClass' => 'language-%s',
// 'codeText' => null, #reserved
// 'codeBlockText' => null, #reserved
'codeBlockAttrParent' => false,
'tableClass' => null,
'tableAlignClass' => null,
'footnoteLinkId' => 'fn:%s',
'footnoteBacklinkId' => 'fnref%s:%s',
'footnoteClass' => 'footnotes',
'footnoteLinkClass' => 'footnote-ref',
'footnoteBacklinkClass' => 'footnote-backref',
'footnoteLinkText' => null,
'footnoteBacklinkText' => '↩',
];
}
/**
* Render input fields on config Page.
* @return Inputfields
*/
public function getInputFields()
{
// Start inputfields
$inputfields = parent::getInputfields();
// Information
$inputfields->add($this->buildInputField('InputfieldMarkup', array(
'id' => 'information',
'value' =>
'<p><b>TextformatterParsedownExtraPlugin</b> is powered by <a href="https://github.com/tovic/parsedown-extra-plugin" title="Open project page in a new tab" target="_blank">ParsedownExtraPlugin</a>, which gives a boost of extra functionality to your markdown.</p>'.
'<p>To add classes, IDs, and other attributes to an element that is not a paragraph, simply suffix that element with <code>{.class #id}</code> for classes and IDs or <code>{attr=something}</code> for attributes. For example, end a heading like this: <code>## Heading {.clause}</code>, or a link like this <code>[Link](http://url/) {.link}</code>. <a href="https://github.com/tovic/parsedown-extra-plugin#advance-attribute-parser">Learn more about this syntax</a>.</p>'.
'<p>For code blocks, you may now use dot notation (<code>```.php html</code>) to set the language and add a class, or even specify your own class and ID (<code>```{.code-block #baz}</code>). <a href="https://github.com/tovic/parsedown-extra-plugin#code-block-class-without-language--prefix">Learn more about this syntax</a>.</p>'.
'<p><b>You may configure the plugin below:</b></p>',
'collapsed'=>Inputfield::collapsedNo,
)));
// General Options fieldset
$fieldset = $this->buildInputField('InputfieldFieldset', [
'label' => $this->_('General Options'),
]);
// HTML5 Element Suffix
$fieldset->add($this->buildInputField('InputfieldCheckbox', [
'name+id' => 'html5ElementSuffix',
'label' => $this->_('Element Suffix'),
'label2' => $this->_('Use HTML5 element suffix (recommended)'),
'notes' => $this->_("**[Void elements](https://html.spec.whatwg.org/multipage/syntax.html#void-elements)** are those that do not require a closing/end tag because they never contain content.\nThe XHTML doctype uses ' />' as a suffix, and HTML5 uses '>'."),
'collapsed' => Inputfield::collapsedNever,
'autocheck' => true,
]));
// Predefined Abbreviations
$fieldset->add($this->buildInputField('InputfieldTextarea', [
'name+id' => 'abbreviations',
'label' => $this->_('Predefined Abbreviations'),
'description' => $this->_('If you would like the module to automatically wrap specific abbreviations in an `abbr` element, specify those below in the format `**SHORT=Long**`; one on each line:'),
'notes' => $this->_('You can also use a colon as a separator, and either separator may be surrounded by whitespace.'),
'collapsed' => Inputfield::collapsedNever,
]));
$inputfields->add($fieldset);
// Images and Links
$fieldset = $this->buildInputField('InputfieldFieldset', [
'label' => $this->_('Images and Links'),
'description' => $this->_('Use format `**name=value**` and separate each with a comma.'),
]);
// Image Attributes
$fieldset->add($this->buildInputField('InputfieldText', [
'name+id' => 'imageAttributes',
'label' => $this->_('Image Attributes'),
'description' => $this->_('Add the following attributes to **all** images.'),
'notes' => $this->_('**Example:** class=my-image, alt=My Image'),
'collapsed' => Inputfield::collapsedNever,
'monospace' => true,
'columnWidth' => 50,
]));
// External Image Attributes
$fieldset->add($this->buildInputField('InputfieldText', [
'name+id' => 'externalImageAttributes',
'label' => $this->_('External Image Attributes'),
'description' => $this->_('Add the following attributes to **external** images.'),
'notes' => $this->_('**Example:** class=external'),
'collapsed' => Inputfield::collapsedNever,
'monospace' => true,
'columnWidth' => 50,
]));
// Link Attributes
$fieldset->add($this->buildInputField('InputfieldText', [
'name+id' => 'linkAttributes',
'label' => $this->_('Link Attributes'),
'description' => $this->_('Add the following attributes to **all** links.'),
'notes' => $this->_('**Example:** class=my-link, data-plugin=true'),
'collapsed' => Inputfield::collapsedNever,
'monospace' => true,
'columnWidth' => 50,
]));
// External Link Attributes
$fieldset->add($this->buildInputField('InputfieldText', [
'name+id' => 'externalLinkAttributes',
'label' => $this->_('External Link Attributes'),
'description' => $this->_('Add the following attributes to **external** links.'),
'notes' => $this->_('**Example:** target=_blank, rel=nofollow'),
'collapsed' => Inputfield::collapsedNever,
'monospace' => true,
'columnWidth' => 50,
]));
$inputfields->add($fieldset);
// Code Blocks
$fieldset = $this->buildInputField('InputfieldFieldset', [
'label' => $this->_('Code Blocks'),
]);
// Code Block Class
$fieldset->add($this->buildInputField('InputfieldText', [
'name+id' => 'codeClass',
// 'label' => $this->_('Class'),
'skipLabel' => Inputfield::skipLabelHeader,
'description' => $this->_('Use the following class for code blocks:'),
'notes' => $this->_('**Note:** `%s` is a placeholder for the name of the language. Default is `language-%s` (blank is also default).'),
'collapsed' => Inputfield::collapsedNever,
'monospace' => true,
'columnWidth' => 50,
]));
// Use code attributes on parent (<pre>)
$fieldset->add($this->buildInputField('InputfieldCheckbox', [
'name+id' => 'codeBlockAttrParent',
'label' => $this->_('Parent Attributes'),
'label2' => $this->_('Place code block attributes on their parent element'),
'notes' => $this->_("When enabled, attributes given to `<code>` elements are instead placed on their parent `<pre>` elements."),
'collapsed' => Inputfield::collapsedNever,
'autocheck' => true,
'columnWidth' => 50,
]));
$inputfields->add($fieldset);
// Tables
$fieldset = $this->buildInputField('InputfieldFieldset', [
'label' => $this->_('Tables'),
]);
// Table Class
$fieldset->add($this->buildInputField('InputfieldText', [
'name+id' => 'tableClass',
'label' => $this->_('Table Class'),
'description' => $this->_('Use the following class for tables:'),
'notes' => $this->_("If you specify an integer, the `border` attribute will be set.\nOtherwise, your input will be applied to the `class` attribute."),
'collapsed' => Inputfield::collapsedNever,
'monospace' => true,
'columnWidth' => 50,
]));
// Table Alignment Class
$fieldset->add($this->buildInputField('InputfieldText', [
'name+id' => 'tableAlignClass',
'label' => $this->_('Table Alignment Class'),
'description' => $this->_('Use the following class for table-alignment:'),
'notes' => $this->_('**Example:** `text-%s`, where `%s` is the alignment of the table.'),
'collapsed' => Inputfield::collapsedNever,
'monospace' => true,
'columnWidth' => 50,
]));
$inputfields->add($fieldset);
// Footnotes
$fieldset = $this->buildInputField('InputfieldFieldset', [
'label' => $this->_('Footnotes'),
]);
// Footnote Block Class
$fieldset->add($this->buildInputField('InputfieldText', [
'name+id' => 'footnoteClass',
'label' => $this->_('Block Class'),
'description' => $this->_('Use the following class for the footnotes block:'),
'notes' => $this->_('**Example:** `cite-refs`'),
'collapsed' => Inputfield::collapsedNever,
'monospace' => true,
]));
// Footnote Link ID Format
$fieldset->add($this->buildInputField('InputfieldText', [
'name+id' => 'footnoteLinkId',
'label' => $this->_('Link ID Format'),
'description' => $this->_('Use the following ID format for footnote references:'),
'notes' => $this->_('**Example:** `cite_note:%s`, where `%s` is the footnote reference number.'),
'collapsed' => Inputfield::collapsedNever,
'monospace' => true,
'columnWidth' => 50,
]));
// Footnote Backlink ID Format
$fieldset->add($this->buildInputField('InputfieldText', [
'name+id' => 'footnoteBacklinkId',
'label' => $this->_('Backlink ID Format'),
'description' => $this->_('Use the following ID format for footnote backlink references:'),
'notes' => $this->_('**Example:** `cite_ref:%s`, where `%s` is the footnote backlink reference number.'),
'collapsed' => Inputfield::collapsedNever,
'monospace' => true,
'columnWidth' => 50,
]));
// Footnote Link Class
$fieldset->add($this->buildInputField('InputfieldText', [
'name+id' => 'footnoteLinkClass',
'label' => $this->_('Link Class'),
'description' => $this->_('Use the following class for footnote links:'),
'notes' => $this->_('**Example:** `cite-ref`'),
'collapsed' => Inputfield::collapsedNever,
'monospace' => true,
'columnWidth' => 50,
]));
// Footnote Backlink Class
$fieldset->add($this->buildInputField('InputfieldText', [
'name+id' => 'footnoteBacklinkClass',
'label' => $this->_('Backlink Class'),
'description' => $this->_('Use the following class for footnote backlinks:'),
'notes' => $this->_('**Example:** `cite-backref`'),
'collapsed' => Inputfield::collapsedNever,
'monospace' => true,
'columnWidth' => 50,
]));
// Footnote Link Text
$fieldset->add($this->buildInputField('InputfieldText', [
'name+id' => 'footnoteLinkText',
'label' => $this->_('Link Text'),
'description' => $this->_('Use the following format for footnote links:'),
'notes' => $this->_('**Example:** `[%s]`, where `%s` is the footnote reference number.'),
'collapsed' => Inputfield::collapsedNever,
'monospace' => true,
'columnWidth' => 50,
]));
// Footnote Backlink Text
$fieldset->add($this->buildInputField('InputfieldText', [
'name+id' => 'footnoteBacklinkText',
'label' => $this->_('Backlink Text'),
'description' => $this->_('Use the following format for footnote backlinks:'),
'notes' => $this->_('**Example:** `<i class="icon icon-back"></i>` - default is ↩ (`&#8617;`)'),
'collapsed' => Inputfield::collapsedNever,
'monospace' => true,
'columnWidth' => 50,
]));
$inputfields->add($fieldset);
return $inputfields;
}
/**
* Given a fieldtype, create, populate, and return an Inputfield
* @param string $fieldNameId
* @param array $meta
* @return Inputfield
*/
protected function buildInputField($fieldNameId, $meta)
{
$field = wire('modules')->get($fieldNameId);
foreach ($meta as $metaNames => $metaInfo) {
$metaNames = explode('+', $metaNames);
foreach ($metaNames as $metaName) {
$field->$metaName = $metaInfo;
if ($metaName === 'monospace' && $metaInfo === true) {
$field->setAttribute('style',
"font-family:Menlo,Monaco,'Andale Mono','Lucida Console','Courier New',monospace;".
"font-size:14px;padding:4px"
);
}
}
}
return $field;
}
}