Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 8ee7c3b4a98e45a66de8b2d31878249a8694227a (plain) (blame)
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
/*******************************************************************************
 * Copyright (c) 2012 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;

import org.eclipse.mylyn.wikitext.tests.TestUtil;

/**
 * Tests for Markdown overview and miscellaneous. Follows specification at
 * <a>http://daringfireball.net/projects/markdown/syntax#overview</a>.
 * <a>http://daringfireball.net/projects/markdown/syntax#misc</a>.
 * 
 * @author Stefan Seelmann
 */
public class MarkdownLanguageMiscellaneousTest extends MarkdownLanguageTestBase {

	public void testEmptyLine() {
		String html = parseToHtml("    ");
		TestUtil.println("HTML: " + html);
		assertEquals("", html);
	}

	/*
	 * Inline HTML. For any markup that is not covered by Markdown's syntax, you simply use HTML itself. There's no need
	 * to preface it or delimit it to indicate that you’re switching from Markdown to HTML; you just use the tags. The
	 * only restrictions are that block-level HTML elements - e.g. div, table,pre, p, etc. - must be separated from
	 * surrounding content by blank lines, and the start and end tags of the block should not be indented with tabs or
	 * spaces. Markdown is smart enough not to add extra (unwanted) p tags around HTML block-level tags.
	 */
	public void testInlineHtml() throws Exception {
		String html = parseToHtml("aaa\n\n<table>\n <tr>\n  <td>Foo</td>\n </tr>\n</table>\n\nbbb");
		TestUtil.println("HTML: " + html);
		assertEquals("<p>aaa</p>\n<table>\n <tr>\n  <td>Foo</td>\n </tr>\n</table>\n<p>bbb</p>\n", html);
	}

	/*
	 * Note that Markdown formatting syntax is not processed within block-level HTML tags. E.g., you can't use
	 * Markdown-style *emphasis* inside an HTML block.
	 */
	public void testNoProcessingWithinInlineHtmlBlockLevelTags() throws Exception {
		String html = parseToHtml("<div>*Foo*</div>");
		TestUtil.println("HTML: " + html);
		assertEquals("<div>*Foo*</div>\n", html);
	}

	/*
	 * Span-level HTML tags - e.g. span, cite, or del - can be used anywhere in a Markdown paragraph, list item, or
	 * header. If you want, you can even use HTML tags instead of Markdown formatting; e.g. if you'd prefer to use HTML
	 * a or img tags instead of Markdown's link or image syntax, go right ahead.
	 */
	public void testSpanLevelTags() throws Exception {
		String html = parseToHtml("Image: <img src=\"image.jpg\">some nice image</img>.");
		TestUtil.println("HTML: " + html);
		assertEquals("<p>Image: <img src=\"image.jpg\">some nice image</img>.</p>\n", html);

	}

	/*
	 * Unlike block-level HTML tags, Markdown syntax is processed within span-level tags.
	 */
	public void testProcessingInSpanLevelTags() throws Exception {
		String html = parseToHtml("Image: <img src=\"image.jpg\">some **nice** image</img>.");
		TestUtil.println("HTML: " + html);
		assertEquals("<p>Image: <img src=\"image.jpg\">some <strong>nice</strong> image</img>.</p>\n", html);
	}

	/*
	 * Automatic Escaping for Special Characters. Markdown allows you to use these characters naturally, taking care of
	 * all the necessary escaping for you. If you use an ampersand as part of an HTML entity, it remains unchanged;
	 * otherwise it will be translated into &amp;. So, if you want to include a copyright symbol in your article, you
	 * can write: &copy; and Markdown will leave it alone.
	 */
	public void testPreserveHtmlEntities() {
		String copy = parseToHtml("&copy; &amp;");
		TestUtil.println("HTML: " + copy);
		assertEquals("<p>&copy; &amp;</p>\n", copy);
	}

	/*
	 * But if you write: AT&T Markdown will translate it to: AT&amp;T. 
	 */
	public void testAmpersandIsEscaped() {
		String amp = parseToHtml("AT&T, a & b");
		TestUtil.println("HTML: " + amp);
		assertEquals("<p>AT&amp;T, a &amp; b</p>\n", amp);

		String urlWithAmp = parseToHtml("http://images.google.com/images?num=30&q=larry+bird");
		TestUtil.println("HTML: " + urlWithAmp);
		assertEquals("<p>http://images.google.com/images?num=30&amp;q=larry+bird</p>\n", urlWithAmp);
	}

	/* 
	 * Similarly, because Markdown supports inline HTML, if you use angle brackets as delimiters for HTML tags, Markdown 
	 * will treat them as such. But if you write: 4 < 5 Markdown will translate it to: 4 &lt; 5
	 */
	public void testAngleBracketsAreEscaped() {
		String lt = parseToHtml("4 < 5");
		TestUtil.println("HTML: " + lt);
		assertEquals("<p>4 &lt; 5</p>\n", lt);

		String gt = parseToHtml("6 > 5");
		TestUtil.println("HTML: " + gt);
		assertEquals("<p>6 &gt; 5</p>\n", gt);
	}

	/*
	 * Backslash Escapes. Markdown allows you to use backslash escapes to generate literal characters which would otherwise have special
	 * meaning in Markdown's formatting syntax.
	 */
	public void testEscapedBackslash() {
		assertEquals("<p>\\</p>\n", parseToHtml("\\\\"));
	}

	public void testEscapedBacktick() {
		assertEquals("<p>`</p>\n", parseToHtml("\\`"));
	}

	public void testEscapedAsterisk() {
		assertEquals("<p>*</p>\n", parseToHtml("\\*"));
	}

	public void testEscapedUnderscore() {
		assertEquals("<p>_</p>\n", parseToHtml("\\_"));
	}

	public void testEscapedOpeningCurlyBrace() {
		assertEquals("<p>{</p>\n", parseToHtml("\\{"));
	}

	public void testEscapedClosingCurlyBrace() {
		assertEquals("<p>}</p>\n", parseToHtml("\\}"));
	}

	public void testEscapedOpeningSquareBracket() {
		assertEquals("<p>[</p>\n", parseToHtml("\\["));
	}

	public void testEscapedClosingSquareBracket() {
		assertEquals("<p>]</p>\n", parseToHtml("\\]"));
	}

	public void testEscapedOpeningParenthesis() {
		assertEquals("<p>(</p>\n", parseToHtml("\\("));
	}

	public void testEscapedClosingParenthesis() {
		assertEquals("<p>)</p>\n", parseToHtml("\\)"));
	}

	public void testEscapedHashMark() {
		assertEquals("<p>#</p>\n", parseToHtml("\\#"));
	}

	public void testEscapedPlusSign() {
		assertEquals("<p>+</p>\n", parseToHtml("\\+"));
	}

	public void testEscapedMinusSign() {
		assertEquals("<p>-</p>\n", parseToHtml("\\-"));
	}

	public void testEscapedDot() {
		assertEquals("<p>.</p>\n", parseToHtml("\\."));
	}

	public void testEscapedExclamationMark() {
		assertEquals("<p>!</p>\n", parseToHtml("\\!"));
	}

}

Back to the top