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
|
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>GitlabMarkdownHelper</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link rel="stylesheet" href="../css/reset.css" type="text/css" media="screen" />
<link rel="stylesheet" href="../css/main.css" type="text/css" media="screen" />
<link rel="stylesheet" href="../css/github.css" type="text/css" media="screen" />
<script src="../js/jquery-1.3.2.min.js" type="text/javascript" charset="utf-8"></script>
<script src="../js/jquery-effect.js" type="text/javascript" charset="utf-8"></script>
<script src="../js/main.js" type="text/javascript" charset="utf-8"></script>
<script src="../js/highlight.pack.js" type="text/javascript" charset="utf-8"></script>
</head>
<body>
<div class="banner">
<h1>
<span class="type">Module</span>
GitlabMarkdownHelper
</h1>
<ul class="files">
<li><a href="../files/app/helpers/gitlab_markdown_helper_rb.html">app/helpers/gitlab_markdown_helper.rb</a></li>
</ul>
</div>
<div id="bodyContent">
<div id="content">
<!-- Method ref -->
<div class="sectiontitle">Methods</div>
<dl class="methods">
<dt>L</dt>
<dd>
<ul>
<li>
<a href="#method-i-link_to_gfm">link_to_gfm</a>
</li>
</ul>
</dd>
<dt>M</dt>
<dd>
<ul>
<li>
<a href="#method-i-markdown">markdown</a>
</li>
</ul>
</dd>
</dl>
<!-- Includes -->
<div class="sectiontitle">Included Modules</div>
<ul>
<li>
<a href="Gitlab/Markdown.html">
Gitlab::Markdown
</a>
</li>
</ul>
<!-- Methods -->
<div class="sectiontitle">Instance Public methods</div>
<div class="method">
<div class="title method-title" id="method-i-link_to_gfm">
<b>link_to_gfm</b>(body, url, html_options = {})
<a href="../classes/GitlabMarkdownHelper.html#method-i-link_to_gfm" name="method-i-link_to_gfm" class="permalink">Link</a>
</div>
<div class="description">
<p>Use this in places where you would normally use link_to(gfm(…), …).</p>
<p>It solves a problem occurring with nested links (i.e. “<a>outer text
<a>gfm ref</a> more outer text</a>”). This will not be
interpreted as intended. Browsers will parse something like “<a>outer
text </a><a>gfm ref</a> more outer text” (notice the last
part is not linked any more). <a
href="GitlabMarkdownHelper.html#method-i-link_to_gfm">#link_to_gfm</a>
corrects that. It wraps all parts to explicitly produce the correct linking
behavior (i.e. “<a>outer text </a><a>gfm
ref</a><a> more outer text</a>”).</p>
</div>
<div class="sourcecode">
<p class="source-link">
Source:
<a href="javascript:toggleSource('method-i-link_to_gfm_source')" id="l_method-i-link_to_gfm_source">show</a>
</p>
<div id="method-i-link_to_gfm_source" class="dyn-source">
<pre><span class="ruby-comment"># File app/helpers/gitlab_markdown_helper.rb, line 13</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">link_to_gfm</span>(<span class="ruby-identifier">body</span>, <span class="ruby-identifier">url</span>, <span class="ruby-identifier">html_options</span> = {})
<span class="ruby-keyword">return</span> <span class="ruby-string">""</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">body</span>.<span class="ruby-identifier">blank?</span>
<span class="ruby-identifier">gfm_body</span> = <span class="ruby-identifier">gfm</span>(<span class="ruby-identifier">escape_once</span>(<span class="ruby-identifier">body</span>), <span class="ruby-identifier">html_options</span>)
<span class="ruby-identifier">gfm_body</span>.<span class="ruby-identifier">gsub!</span>(<span class="ruby-regexp">%r{<a.*?>.*?</a>}</span>) <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">match</span><span class="ruby-operator">|</span>
<span class="ruby-node">"</a>#{match}#{link_to("", url, html_options)[0..-5]}"</span> <span class="ruby-comment"># "</a>".length +1</span>
<span class="ruby-keyword">end</span>
<span class="ruby-identifier">link_to</span>(<span class="ruby-identifier">gfm_body</span>.<span class="ruby-identifier">html_safe</span>, <span class="ruby-identifier">url</span>, <span class="ruby-identifier">html_options</span>)
<span class="ruby-keyword">end</span></pre>
</div>
</div>
</div>
<div class="method">
<div class="title method-title" id="method-i-markdown">
<b>markdown</b>(text)
<a href="../classes/GitlabMarkdownHelper.html#method-i-markdown" name="method-i-markdown" class="permalink">Link</a>
</div>
<div class="description">
</div>
<div class="sourcecode">
<p class="source-link">
Source:
<a href="javascript:toggleSource('method-i-markdown_source')" id="l_method-i-markdown_source">show</a>
</p>
<div id="method-i-markdown_source" class="dyn-source">
<pre><span class="ruby-comment"># File app/helpers/gitlab_markdown_helper.rb, line 25</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">markdown</span>(<span class="ruby-identifier">text</span>)
<span class="ruby-keyword">unless</span> <span class="ruby-ivar">@markdown</span>
<span class="ruby-identifier">gitlab_renderer</span> = <span class="ruby-constant">Redcarpet</span><span class="ruby-operator">::</span><span class="ruby-constant">Render</span><span class="ruby-operator">::</span><span class="ruby-constant">GitlabHTML</span>.<span class="ruby-identifier">new</span>(<span class="ruby-keyword">self</span>,
<span class="ruby-comment"># see https://github.com/vmg/redcarpet#darling-i-packed-you-a-couple-renderers-for-lunch-</span>
<span class="ruby-identifier">filter_html</span><span class="ruby-operator">:</span> <span class="ruby-keyword">true</span>,
<span class="ruby-identifier">with_toc_data</span><span class="ruby-operator">:</span> <span class="ruby-keyword">true</span>,
<span class="ruby-identifier">hard_wrap</span><span class="ruby-operator">:</span> <span class="ruby-keyword">true</span>)
<span class="ruby-ivar">@markdown</span> = <span class="ruby-constant">Redcarpet</span><span class="ruby-operator">::</span><span class="ruby-constant">Markdown</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">gitlab_renderer</span>,
<span class="ruby-comment"># see https://github.com/vmg/redcarpet#and-its-like-really-simple-to-use</span>
<span class="ruby-identifier">no_intra_emphasis</span><span class="ruby-operator">:</span> <span class="ruby-keyword">true</span>,
<span class="ruby-identifier">tables</span><span class="ruby-operator">:</span> <span class="ruby-keyword">true</span>,
<span class="ruby-identifier">fenced_code_blocks</span><span class="ruby-operator">:</span> <span class="ruby-keyword">true</span>,
<span class="ruby-identifier">autolink</span><span class="ruby-operator">:</span> <span class="ruby-keyword">true</span>,
<span class="ruby-identifier">strikethrough</span><span class="ruby-operator">:</span> <span class="ruby-keyword">true</span>,
<span class="ruby-identifier">lax_html_blocks</span><span class="ruby-operator">:</span> <span class="ruby-keyword">true</span>,
<span class="ruby-identifier">space_after_headers</span><span class="ruby-operator">:</span> <span class="ruby-keyword">true</span>,
<span class="ruby-identifier">superscript</span><span class="ruby-operator">:</span> <span class="ruby-keyword">true</span>)
<span class="ruby-keyword">end</span>
<span class="ruby-ivar">@markdown</span>.<span class="ruby-identifier">render</span>(<span class="ruby-identifier">text</span>).<span class="ruby-identifier">html_safe</span>
<span class="ruby-keyword">end</span></pre>
</div>
</div>
</div>
</div>
</div>
</body>
</html>
|