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
|
/*******************************************************************************
* Copyright (c) 2012, 2013 Stefan Seelmann and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Stefan Seelmann - initial API and implementation
*******************************************************************************/
package org.eclipse.mylyn.internal.wikitext.markdown.tests;
/**
* Tests for Markdown span elements. Follows specification at
* <a>http://daringfireball.net/projects/markdown/syntax#span</a>.
*
* @author Stefan Seelmann
*/
public class MarkdownLanguageSpanElementsTest extends MarkdownLanguageTestBase {
/*
* Links. To create an inline link, use a set of regular parentheses immediately after the link text's
* closing square bracket. Inside the parentheses, put the URL where you want the link to point, along
* with an optional title for the link, surrounded in quotes.
*/
public void testInlineLinkWithTitle() {
String markup = "This is [ an example ](http://example.com/ \"Title\") inline link.";
String expectedHtml = "<p>This is <a href=\"http://example.com/\" title=\"Title\">an example</a> inline link.</p>\n";
parseAndAssert(markup, expectedHtml);
}
public void testInlineLinkWithoutTitle() {
String markup = "[This link](http://example.net/) has no title attribute.";
String expectedHtml = "<p><a href=\"http://example.net/\">This link</a> has no title attribute.</p>\n";
parseAndAssert(markup, expectedHtml);
}
/*
* If you're referring to a local resource on the same server, you can use relative paths:
*/
public void testInlineLinkAsRelativePath() {
String markup = "See my [About](/about/) page for details.";
String expectedHtml = "<p>See my <a href=\"/about/\">About</a> page for details.</p>\n";
parseAndAssert(markup, expectedHtml);
}
public void testNoSpanWithinInlineLinks() throws Exception {
String markup = "[Test](http://www.google.de/?q=t_es_t)";
String expectedHtml = "<p><a href=\"http://www.google.de/?q=t_es_t\">Test</a></p>\n";
parseAndAssert(markup, expectedHtml);
}
/*
* Reference-style links use a second set of square brackets, inside which you place a label of your choosing to
* identify the link. Then, anywhere in the document, you define your link label like this, on a line by itself.
* Link definitions are only used for creating links during Markdown processing, and are stripped from your
* document in the HTML output.
* Note: Reference parsing is tested in LinkReferencesTest.
*/
public void testReferenceStyleLink() {
String markup = "This is [an example][id] reference-style link.\n\n[id]: http://example.com/ \"Optional Title Here\"";
String expectedHtml = "<p>This is <a href=\"http://example.com/\" title=\"Optional Title Here\">an example</a> reference-style link.</p>\n";
parseAndAssert(markup, expectedHtml);
}
/*
* You can optionally use a space to separate the sets of brackets
*/
public void testReferenceStyleLinkWithSpace() {
String markup = "This is [an example] [id] reference-style link.\n\n[id]: http://example.com/ \"Optional Title Here\"";
String expectedHtml = "<p>This is <a href=\"http://example.com/\" title=\"Optional Title Here\">an example</a> reference-style link.</p>\n";
parseAndAssert(markup, expectedHtml);
}
/*
* Link definition names may consist of letters, numbers, spaces, and punctuation.
*/
public void testReferenceStyleLinkNameAllowedCharacters() {
String markup = "[Link][A-Z 1.0]\n\n[A-Z 1.0]: http://example.com/";
String expectedHtml = "<p><a href=\"http://example.com/\">Link</a></p>\n";
parseAndAssert(markup, expectedHtml);
}
/*
* But they are not case sensitive. E.g. these two links: [link text][a] and [link text][A] are equivalent.
*/
public void testReferenceStyleLinkNameIsNotCaseSensitive() {
String markup = "[link text a][a] and [LINK TEXT A][A].\n\n[A]: http://example.com/";
String expectedHtml = "<p><a href=\"http://example.com/\">link text a</a> and <a href=\"http://example.com/\">LINK TEXT A</a>.</p>\n";
parseAndAssert(markup, expectedHtml);
}
/*
* The implicit link name shortcut allows you to omit the name of the link, in which case the link text itself
* is used as the name. Just use an empty set of square brackets.
*/
public void testReferenceStyleLinkWithoutName() {
String markup = "[Google][]\n\n[Google]: http://google.com/";
String expectedHtml = "<p><a href=\"http://google.com/\">Google</a></p>\n";
parseAndAssert(markup, expectedHtml);
}
/*
* Because link names may contain spaces, this shortcut even works for multiple words in the link text.
*/
public void testReferenceStyleLinkWithoutName2() {
String markup = "Visit [Daring Fireball][] for more information.\n\n[Daring Fireball]: http://daringfireball.net/";
String expectedHtml = "<p>Visit <a href=\"http://daringfireball.net/\">Daring Fireball</a> for more information.</p>\n";
parseAndAssert(markup, expectedHtml);
}
public void testReferenceStyleLinkWithMissingReference() {
String markup = "This is a [link][a] with missing reference.\n\n[b]: http://example.com/";
String expectedHtml = "<p>This is a [link][a] with missing reference.</p>\n";
parseAndAssert(markup, expectedHtml);
}
public void testNoSpanWithinReferenceStyleLinks() throws Exception {
String markup = "[Test][test]\n\n[test]: http://www.google.de/?q=t_es_t";
String expectedHtml = "<p><a href=\"http://www.google.de/?q=t_es_t\">Test</a></p>\n";
parseAndAssert(markup, expectedHtml);
}
public void testNoLinkProcessingWithinCodeBlock() throws Exception {
String markup = " Code block [no link](http://example.com/).";
String expectedHtml = "<pre><code>Code block [no link](http://example.com/).</code></pre>";
parseAndAssert(markup, expectedHtml);
}
public void testNoLinkProcessingWithinInlineHtmlBlock() throws Exception {
String markup = "<p>Inline html [no link](http://example.com/).</p>";
String expectedHtml = "<p>Inline html [no link](http://example.com/).</p>\n";
parseAndAssert(markup, expectedHtml);
}
public void testInlineLinkProcessingWithinAtxStyleHeading() throws Exception {
String markup = "# Heading with [link](http://example.com/).";
String expectedHtml = "<h1>Heading with <a href=\"http://example.com/\">link</a>.</h1>";
parseAndAssert(markup, expectedHtml);
}
public void testReferenceLinkProcessingWithinAtxStyleHeading() throws Exception {
String markup = "# Heading with [link][].\n\n[link]: http://example.com/";
String expectedHtml = "<h1>Heading with <a href=\"http://example.com/\">link</a>.</h1>";
parseAndAssert(markup, expectedHtml);
}
public void testInlineLinkProcessingWithinUnderlinedHeading() throws Exception {
String markup = "Heading with [link](http://example.com/).\n===";
String expectedHtml = "<h1>Heading with <a href=\"http://example.com/\">link</a>.</h1>";
parseAndAssert(markup, expectedHtml);
}
public void testReferenceLinkProcessingWithinUnderlinedHeading() throws Exception {
String markup = "Heading with [link][].\n===\n\n[link]: http://example.com/";
String expectedHtml = "<h1>Heading with <a href=\"http://example.com/\">link</a>.</h1>";
parseAndAssert(markup, expectedHtml);
}
public void testLinkProcessingWithinBlockQuote() throws Exception {
String markup = "> Block quote [link](http://example.com/).";
String expectedHtml = "<blockquote><p>Block quote <a href=\"http://example.com/\">link</a>.</p>\n</blockquote>";
parseAndAssert(markup, expectedHtml);
}
/*
* Inline image syntax
*/
public void testInlineImageWithTitle() {
String markup = "![Alt text](/path/to/img.jpg \"Optional title\")";
String expectedHtml = "<p><img alt=\"Alt text\" title=\"Optional title\" border=\"0\" src=\"/path/to/img.jpg\"/></p>\n";
parseAndAssert(markup, expectedHtml);
}
public void testInlineImageWithoutTitle() {
String markup = "![Alt text](/path/to/img.jpg)";
String expectedHtml = "<p><img alt=\"Alt text\" border=\"0\" src=\"/path/to/img.jpg\"/></p>\n";
parseAndAssert(markup, expectedHtml);
}
public void testNoSpanWithinInlineImage() throws Exception {
String markup = "![Alt text](/path/to/my_nice_image.jpg)";
String expectedHtml = "<p><img alt=\"Alt text\" border=\"0\" src=\"/path/to/my_nice_image.jpg\"/></p>\n";
parseAndAssert(markup, expectedHtml);
}
/*
* Reference-style image syntax
*/
public void testReferenceStyleImage() {
String markup = "![Alt text][id]\n\n[id]: url/to/image \"Optional title attribute\"";
String expectedHtml = "<p><img alt=\"Alt text\" title=\"Optional title attribute\" border=\"0\" src=\"url/to/image\"/></p>\n";
parseAndAssert(markup, expectedHtml);
}
public void testNoSpanWithinReferenceStyleImage() {
String markup = "![Alt text][id]\n\n[id]: /path/to/my_nice_image.jpg";
String expectedHtml = "<p><img alt=\"Alt text\" border=\"0\" src=\"/path/to/my_nice_image.jpg\"/></p>\n";
parseAndAssert(markup, expectedHtml);
}
/*
* Emphasis. Markdown treats asterisks * and underscores _ as indicators of emphasis. Text wrapped with one * or _ will be
* wrapped with an HTML em tag; double **'s or __ will be wrapped with an HTML strong tag.
*/
public void testEmphasisWithAsterisks() {
parseAndAssert("*foo bar*", "<p><em>foo bar</em></p>\n");
}
public void testEmphasisWithUnderscore() {
parseAndAssert("_foo bar_", "<p><em>foo bar</em></p>\n");
}
public void testStrongWithAsterisks() {
parseAndAssert("**foo bar**", "<p><strong>foo bar</strong></p>\n");
}
public void testStrongWithUnderscore() {
parseAndAssert("__foo bar__", "<p><strong>foo bar</strong></p>\n");
}
/*
* Emphasis can be used in the middle of a word.
*/
public void testEmphasisWithinWord() {
parseAndAssert("un*frigging*believable", "<p>un<em>frigging</em>believable</p>\n");
}
/*
* But if you surround an * or _ with spaces, it'll be treated as a literal asterisk or underscore.
*/
public void testLiteralAsteriskAndUnderscore() {
parseAndAssert("asterisk * underscore _", "<p>asterisk * underscore _</p>\n");
}
/*
* To produce a literal asterisk or underscore at a position where it would otherwise be used as an emphasis
* delimiter, you can backslash escape it.
*/
public void testEscapesAsterisk() {
parseAndAssert("\\*foo bar\\*", "<p>*foo bar*</p>\n");
}
public void testEscapesUnderscore() {
parseAndAssert("\\_foo bar\\_", "<p>_foo bar_</p>\n");
}
public void testEscapesDoubleAsterisk() {
parseAndAssert("\\**foo bar\\**", "<p>**foo bar**</p>\n");
}
public void testEscapesDoubleUnderscore() {
parseAndAssert("\\__foo bar\\__", "<p>__foo bar__</p>\n");
}
/*
* Code. To indicate a span of code, wrap it with backtick quotes.
*/
public void testCodeSpan() {
String markup = "Use the `printf()` function.";
String expectedHtml = "<p>Use the <code>printf()</code> function.</p>\n";
parseAndAssert(markup, expectedHtml);
}
/*
* To include a literal backtick character within a code span, you can use multiple backticks as the opening and
* closing delimiters.
*/
public void testLiteralBacktickInCodeSpan() {
String markup = "``There is a literal backtick (`) here.``";
String expectedHtml = "<p><code>There is a literal backtick (`) here.</code></p>\n";
parseAndAssert(markup, expectedHtml);
}
/*
* The backtick delimiters surrounding a code span may include spaces - one after the opening, one before the
* closing. This allows you to place literal backtick characters at the beginning or end of a code span:
*/
public void testLiteralBacktickAtBeginnionOrIndOfCodeSpan() {
parseAndAssert("`` `foo` ``", "<p><code>`foo`</code></p>\n");
}
/*
* With a code span, ampersands and angle brackets are encoded as HTML entities automatically
*/
public void testCodeSpanEncodesAmpersandsAndAngleBrackets() {
String markup = "`Encode tags <p> and enties &code;`";
String expectedHtml = "<p><code>Encode tags <p> and enties &code;</code></p>\n";
parseAndAssert(markup, expectedHtml);
}
public void testNoProcessingInCodeSpan() {
String markup = "`Preserve *asterisk*.`";
String expectedHtml = "<p><code>Preserve *asterisk*.</code></p>\n";
parseAndAssert(markup, expectedHtml);
}
}
|