Class: TextLine
Constant Summary
collapse
- @@lazy_doc_id_dict =
{}
Class Method Summary
collapse
Instance Method Summary
collapse
Class Method Details
.add_lazy_doc_id(id) ⇒ Object
350
351
352
353
|
# File 'lib/almirah/doc_items/text_line.rb', line 350
def self.add_lazy_doc_id(id)
doc_id = id.to_s.downcase
@@lazy_doc_id_dict[doc_id] = doc_id
end
|
Instance Method Details
#bold(str) ⇒ Object
365
366
367
|
# File 'lib/almirah/doc_items/text_line.rb', line 365
def bold(str)
"<b>#{str}</b>"
end
|
#bold_and_italic(str) ⇒ Object
369
370
371
|
# File 'lib/almirah/doc_items/text_line.rb', line 369
def bold_and_italic(str)
"<b><i>#{str}</i></b>"
end
|
355
356
357
358
359
|
# File 'lib/almirah/doc_items/text_line.rb', line 355
def format_string(str)
tlp = TextLineParser.new
tlb = TextLineBuilder.new(self)
tlb.restore(tlp.tokenize(str))
end
|
#inline_code(str) ⇒ Object
373
374
375
|
# File 'lib/almirah/doc_items/text_line.rb', line 373
def inline_code(str)
"<code class=\"inline\">#{CGI.escapeHTML(str)}</code>"
end
|
#italic(str) ⇒ Object
361
362
363
|
# File 'lib/almirah/doc_items/text_line.rb', line 361
def italic(str)
"<i>#{str}</i>"
end
|
#link(link_text, link_url) ⇒ Object
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
|
# File 'lib/almirah/doc_items/text_line.rb', line 377
def link(link_text, link_url)
result = "<a target=\"_blank\" rel=\"noopener\" href=\"#{link_url}\" class=\"external\">#{link_text}</a>"
lazy_doc_id = nil
anchor = nil
if res = /(\w+)[.]md$/.match(link_url) lazy_doc_id = res[1].to_s.downcase
elsif res = /(\w*)[.]md(#.*)$/.match(link_url) if res && res.length > 2
lazy_doc_id = res[1]
anchor = res[2]
end
end
if lazy_doc_id && @@lazy_doc_id_dict.key?(lazy_doc_id)
result = if anchor
"<a href=\".\\..\\#{lazy_doc_id}\\#{lazy_doc_id}.html#{anchor}\" class=\"external\">#{link_text}</a>"
else
"<a href=\".\\..\\#{lazy_doc_id}\\#{lazy_doc_id}.html\" class=\"external\">#{link_text}</a>"
end
end
result
end
|