Verzeichnisstruktur phpBB-3.2.0
- Veröffentlicht
- 06.01.2017
So funktioniert es
|
Auf das letzte Element klicken. Dies geht jeweils ein Schritt zurück |
Auf das Icon klicken, dies öffnet das Verzeichnis. Nochmal klicken schließt das Verzeichnis. |
|
(Beispiel Datei-Icons)
|
Auf das Icon klicken um den Quellcode anzuzeigen |
Parser.js
001 var pos, table = null, tableTag, tables, text;
002
003 if (config.overwriteMarkdown)
004 {
005 overwriteMarkdown();
006 }
007 if (config.overwriteEscapes)
008 {
009 overwriteEscapes();
010 }
011
012 captureTables();
013 processTables();
014
015 /**
016 * Add current line to a table
017 *
018 * @param {!string} line Line of text
019 */
020 function addLine(line)
021 {
022 var ignoreLen = 0;
023
024 if (!table)
025 {
026 table = { rows: [] };
027
028 // Make the table start at the first non-space character
029 ignoreLen = /^ */.exec(line)[0].length;
030 line = line.substr(ignoreLen);
031 }
032
033 // Overwrite the outermost pipes
034 line = line.replace(/^( *)\|/, '$1 ').replace(/\|( *)$/, ' $1');
035
036 table.rows.push({ line: line, pos: pos + ignoreLen });
037 }
038
039 /**
040 * Process current table's body
041 */
042 function addTableBody()
043 {
044 var i = 1,
045 cnt = table.rows.length;
046 while (++i < cnt)
047 {
048 addTableRow('TD', table.rows[i]);
049 }
050
051 createBodyTags(table.rows[2].pos, pos);
052 }
053
054 /**
055 * Add a cell's tags for current table at current position
056 *
057 * @param {!string} tagName Either TD or TH
058 * @param {!string} align Either "left", "center", "right" or ""
059 */
060 function addTableCell(tagName, align, text)
061 {
062 var startPos = pos,
063 endPos = startPos + text.length,
064 ignoreLen;
065 pos = endPos;
066
067 var m = /^( *).*?( *)$/.exec(text);
068 if (m[1])
069 {
070 ignoreLen = m[1].length;
071 createIgnoreTag(startPos, ignoreLen);
072 startPos += ignoreLen;
073 }
074 if (m[2])
075 {
076 ignoreLen = m[2].length;
077 createIgnoreTag(endPos - ignoreLen, ignoreLen);
078 endPos -= ignoreLen;
079 }
080
081 createCellTags(tagName, startPos, endPos, align);
082 }
083
084 /**
085 * Process current table's head
086 */
087 function addTableHead()
088 {
089 addTableRow('TH', table.rows[0]);
090 createHeadTags(table.rows[0].pos, pos);
091 }
092
093 /**
094 * Process given table row
095 *
096 * @param {!string} tagName Either TD or TH
097 * @param {!Object} row
098 */
099 function addTableRow(tagName, row)
100 {
101 pos = row.pos;
102 row.line.split('|').forEach(function(str, i)
103 {
104 if (i > 0)
105 {
106 createIgnoreTag(pos, 1);
107 ++pos;
108 }
109
110 var align = (!table.cols[i]) ? '' : table.cols[i];
111 addTableCell(tagName, align, str);
112 });
113
114 createRowTags(row.pos, pos);
115 }
116
117 /**
118 * Capture all pipe tables in current text
119 */
120 function captureTables()
121 {
122 table = null;
123 tables = [];
124
125 pos = 0;
126 text.split("\n").forEach(function(line)
127 {
128 if (line.indexOf('|') < 0)
129 {
130 endTable();
131 }
132 else
133 {
134 addLine(line);
135 }
136 pos += 1 + line.length;
137 });
138 endTable();
139 }
140
141 /**
142 * Create a pair of TBODY tags for given text span
143 *
144 * @param {!number} startPos
145 * @param {!number} endPos
146 */
147 function createBodyTags(startPos, endPos)
148 {
149 addTagPair('TBODY', startPos, 0, endPos, 0, -3);
150 }
151
152 /**
153 * Create a pair of TD or TH tags for given text span
154 *
155 * @param {!string} tagName Either TD or TH
156 * @param {!number} startPos
157 * @param {!number} endPos
158 * @param {!string} align Either "left", "center", "right" or ""
159 */
160 function createCellTags(tagName, startPos, endPos, align)
161 {
162 var tag = addTagPair(tagName, startPos, 0, endPos, 0, -1);
163 if (align)
164 {
165 tag.setAttribute('align', align);
166 }
167 }
168
169 /**
170 * Create a pair of THEAD tags for given text span
171 *
172 * @param {!number} startPos
173 * @param {!number} endPos
174 */
175 function createHeadTags(startPos, endPos)
176 {
177 addTagPair('THEAD', startPos, 0, endPos, 0, -3);
178 }
179
180 /**
181 * Create an ignore tag for given text span
182 *
183 * @param {!number} pos
184 * @param {!number} len
185 */
186 function createIgnoreTag(pos, len)
187 {
188 tableTag.cascadeInvalidationTo(addIgnoreTag(pos, len, 1000));
189 }
190
191 /**
192 * Create a pair of TR tags for given text span
193 *
194 * @param {!number} startPos
195 * @param {!number} endPos
196 */
197 function createRowTags(startPos, endPos)
198 {
199 addTagPair('TR', startPos, 0, endPos, 0, -2);
200 }
201
202 /**
203 * Create an ignore tag for given separator row
204 *
205 * @param {!Object} row
206 */
207 function createSeparatorTag(row)
208 {
209 createIgnoreTag(row.pos - 1, 1 + row.line.length);
210 }
211
212 /**
213 * Create a pair of TABLE tags for given text span
214 *
215 * @param {!number} startPos
216 * @param {!number} endPos
217 */
218 function createTableTags(startPos, endPos)
219 {
220 tableTag = addTagPair('TABLE', startPos, 0, endPos, 0, -4);
221 }
222
223 /**
224 * End current buffered table
225 */
226 function endTable()
227 {
228 if (hasValidTable())
229 {
230 table.cols = parseColumnAlignments(table.rows[1].line);
231 tables.push(table);
232 }
233 table = null;
234 }
235
236 /**
237 * Test whether a valid table is currently buffered
238 *
239 * @return {!boolean}
240 */
241 function hasValidTable()
242 {
243 return (table && table.rows.length > 2 && isValidSeparator(table.rows[1].line));
244 }
245
246 /**
247 * Test whether given line is a valid separator
248 *
249 * @param {!string} line
250 * @return {!boolean}
251 */
252 function isValidSeparator(line)
253 {
254 return /^ *:?-+:?(?:(?:\+| *\| *):?-+:?)+ */.test(line);
255 }
256
257 /**
258 * Overwrite right angle brackets in given match
259 *
260 * @param {!string} str
261 * @return {!string}
262 */
263 function overwriteBlockquoteCallback(str)
264 {
265 return str.replace(/>/g, ' ');
266 }
267
268 /**
269 * Overwrite escape sequences in current text
270 */
271 function overwriteEscapes()
272 {
273 if (text.indexOf('\\|') > -1)
274 {
275 text = text.replace(/\\[\\|]/g, '..');
276 }
277 }
278
279 /**
280 * Overwrite backticks in given match
281 *
282 * @param {!string} str
283 * @return string
284 */
285 function overwriteInlineCodeCallback(str)
286 {
287 return str.replace(/\|/g, '.');
288 }
289
290 /**
291 * Overwrite Markdown-style markup in current text
292 */
293 function overwriteMarkdown()
294 {
295 // Overwrite inline code spans
296 if (text.indexOf('`') > -1)
297 {
298 text = text.replace(/`[^`]*`/g, overwriteInlineCodeCallback);
299 }
300
301 // Overwrite blockquotes
302 if (text.indexOf('>') > -1)
303 {
304 text = text.replace(/^(?:> ?)+/gm, overwriteBlockquoteCallback);
305 }
306 }
307
308 /**
309 * Parse and return column alignments in given separator line
310 *
311 * @param {!string} line
312 * @return {!Array<!string>}
313 */
314 function parseColumnAlignments(line)
315 {
316 // Use a bitfield to represent the colons' presence and map it to the CSS value
317 var align = [
318 '',
319 'right',
320 'left',
321 'center'
322 ],
323 cols = [],
324 regexp = /(:?)-+(:?)/g,
325 m;
326
327 while (m = regexp.exec(line))
328 {
329 var key = (m[1] ? 2 : 0) + (m[2] ? 1 : 0);
330 cols.push(align[key]);
331 }
332
333 return cols;
334 }
335
336 /**
337 * Process current table declaration
338 */
339 function processCurrentTable()
340 {
341 var firstRow = table.rows[0],
342 lastRow = table.rows[table.rows.length - 1];
343 createTableTags(firstRow.pos, lastRow.pos + lastRow.line.length);
344
345 addTableHead();
346 createSeparatorTag(table.rows[1]);
347 addTableBody();
348 }
349
350 /**
351 * Process all the captured tables
352 */
353 function processTables()
354 {
355 var i = -1, cnt = tables.length;
356 while (++i < cnt)
357 {
358 table = tables[i];
359 processCurrentTable();
360 }
361 }