Verzeichnisstruktur phpBB-3.3.15
- Veröffentlicht
- 28.08.2024
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 |
Emphasis.js
001 /**
002 * @type {boolean} Whether current EM span is being closed by current emphasis mark
003 */
004 var closeEm;
005
006 /**
007 * @type {boolean} Whether current EM span is being closed by current emphasis mark
008 */
009 var closeStrong;
010
011 /**
012 * @type {number} Starting position of the current EM span in the text
013 */
014 var emPos;
015
016 /**
017 * @type {number} Ending position of the current EM span in the text
018 */
019 var emEndPos;
020
021 /**
022 * @type {number} Number of emphasis characters unused in current span
023 */
024 var remaining;
025
026 /**
027 * @type {number} Starting position of the current STRONG span in the text
028 */
029 var strongPos;
030
031 /**
032 * @type {number} Ending position of the current STRONG span in the text
033 */
034 var strongEndPos;
035
036 function parse()
037 {
038 parseEmphasisByCharacter('*', /\*+/g);
039 parseEmphasisByCharacter('_', /_+/g);
040 }
041
042 /**
043 * Adjust the ending position of current EM and STRONG spans
044 */
045 function adjustEndingPositions()
046 {
047 if (closeEm && closeStrong)
048 {
049 if (emPos < strongPos)
050 {
051 emEndPos += 2;
052 }
053 else
054 {
055 ++strongEndPos;
056 }
057 }
058 }
059
060 /**
061 * Adjust the starting position of current EM and STRONG spans
062 *
063 * If both EM and STRONG are set to start at the same position, we adjust their position
064 * to match the order they are closed. If they start and end at the same position, STRONG
065 * starts before EM to match Markdown's behaviour
066 */
067 function adjustStartingPositions()
068 {
069 if (emPos >= 0 && emPos === strongPos)
070 {
071 if (closeEm)
072 {
073 emPos += 2;
074 }
075 else
076 {
077 ++strongPos;
078 }
079 }
080 }
081
082 /**
083 * End current valid EM and STRONG spans
084 */
085 function closeSpans()
086 {
087 if (closeEm)
088 {
089 --remaining;
090 addTagPair('EM', emPos, 1, emEndPos, 1);
091 emPos = -1;
092 }
093 if (closeStrong)
094 {
095 remaining -= 2;
096 addTagPair('STRONG', strongPos, 2, strongEndPos, 2);
097 strongPos = -1;
098 }
099 }
100
101 /**
102 * Get emphasis markup split by block
103 *
104 * @param {!RegExp} regexp Regexp used to match emphasis
105 * @param {number} pos Position in the text of the first emphasis character
106 * @return {!Array} Each array contains a list of [matchPos, matchLen] pairs
107 */
108 function getEmphasisByBlock(regexp, pos)
109 {
110 var block = [],
111 blocks = [],
112 breakPos = text.indexOf("\x17", pos),
113 m;
114
115 regexp.lastIndex = pos;
116 while (m = regexp.exec(text))
117 {
118 var matchPos = m.index,
119 matchLen = m[0].length;
120
121 // Test whether we've just passed the limits of a block
122 if (matchPos > breakPos)
123 {
124 blocks.push(block);
125 block = [];
126 breakPos = text.indexOf("\x17", matchPos);
127 }
128
129 // Test whether we should ignore this markup
130 if (!ignoreEmphasis(matchPos, matchLen))
131 {
132 block.push([matchPos, matchLen]);
133 }
134 }
135 blocks.push(block);
136
137 return blocks;
138 }
139
140
141 /**
142 * Test whether emphasis should be ignored at the given position in the text
143 *
144 * @param {number} pos Position of the emphasis in the text
145 * @param {number} len Length of the emphasis
146 * @return {boolean}
147 */
148 function ignoreEmphasis(pos, len)
149 {
150 // Ignore single underscores between alphanumeric characters
151 return (text.charAt(pos) === '_' && len === 1 && isSurroundedByAlnum(pos, len));
152 }
153
154 /**
155 * Open EM and STRONG spans whose content starts at given position
156 *
157 * @param {number} pos
158 */
159 function openSpans(pos)
160 {
161 if (remaining & 1)
162 {
163 emPos = pos - remaining;
164 }
165 if (remaining & 2)
166 {
167 strongPos = pos - remaining;
168 }
169 }
170
171 /**
172 * Parse emphasis and strong applied using given character
173 *
174 * @param {string} character Markup character, either * or _
175 * @param {!RegExp} regexp Regexp used to match the series of emphasis character
176 */
177 function parseEmphasisByCharacter(character, regexp)
178 {
179 var pos = text.indexOf(character);
180 if (pos === -1)
181 {
182 return;
183 }
184
185 getEmphasisByBlock(regexp, pos).forEach(processEmphasisBlock);
186 }
187
188
189 /**
190 * Process a list of emphasis markup strings
191 *
192 * @param {!Array<!Array<number>>} block List of [matchPos, matchLen] pairs
193 */
194 function processEmphasisBlock(block)
195 {
196 emPos = -1,
197 strongPos = -1;
198
199 block.forEach(function(pair)
200 {
201 processEmphasisMatch(pair[0], pair[1]);
202 });
203 }
204
205 /**
206 * Process an emphasis mark
207 *
208 * @param {number} matchPos
209 * @param {number} matchLen
210 */
211 function processEmphasisMatch(matchPos, matchLen)
212 {
213 var canOpen = !isBeforeWhitespace(matchPos + matchLen - 1),
214 canClose = !isAfterWhitespace(matchPos),
215 closeLen = (canClose) ? Math.min(matchLen, 3) : 0;
216
217 closeEm = !!(closeLen & 1) && emPos >= 0;
218 closeStrong = !!(closeLen & 2) && strongPos >= 0;
219 emEndPos = matchPos;
220 strongEndPos = matchPos;
221 remaining = matchLen;
222
223 adjustStartingPositions();
224 adjustEndingPositions();
225 closeSpans();
226
227 // Adjust the length of unused markup remaining in current match
228 remaining = (canOpen) ? Math.min(remaining, 3) : 0;
229 openSpans(matchPos + matchLen);
230 }