Class: Eggshell::Bundles::Basic::BasicFormatHandlers
- Inherits:
-
Object
- Object
- Eggshell::Bundles::Basic::BasicFormatHandlers
- Defined in:
- lib/eggshell/bundles/basics.rb
Constant Summary collapse
- TAG_MAP =
{ '[*' => 'b', '[**' => 'strong', '[/' => 'i', '[//' => 'em', '[__' => 'u', '[-' => 'strike', '[^' => 'sup', '[_' => 'sub', '[[' => 'span' }.freeze
- ESCAPE_MAP_HTML =
{ '<' => '<', '>' => '>', '/<' => '«', '>/' => '»', '/\'' => '‘', '\'/' => '’', '/"' => '“', '"/' => '”', 'c' => '©', 'r' => '®', '!' => '¡', '-' => '–', '--' => '—', '&' => '&' }.freeze
Constants included from Eggshell::BlockHandler::HtmlUtils
Eggshell::BlockHandler::HtmlUtils::HASH_HTML_ESCAPE
Instance Method Summary collapse
- #format(tag, str) ⇒ Object
-
#initialize ⇒ BasicFormatHandlers
constructor
A new instance of BasicFormatHandlers.
Methods included from Eggshell::BlockHandler::HtmlUtils
#attrib_string, #create_tag, #css_string, #html_escape
Methods included from FormatHandler::Utils
Methods included from FormatHandler
Constructor Details
#initialize ⇒ BasicFormatHandlers
Returns a new instance of BasicFormatHandlers.
535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 |
# File 'lib/eggshell/bundles/basics.rb', line 535 def initialize @fmt_delimeters = [ ['[*', '*]'], # bold ['[**', '**]'], # strong ['[/', '/]'], # italic ['[//', '//]'], # emphasis ['[__', '__]'], # underline ['[-', '-]'], # strike ['[^', '^]'], # superscript ['[_', '_]'], # subscript, ['[[', ']]'], # span ['[~', '~]'], # anchor ['[!', '!]'], # image ['%{', '}%', true], # entity expansion ['`', '`', '%{'], # code, backtick ['{{', '}}', '%{'] # code, normal ] end |
Instance Method Details
#format(tag, str) ⇒ Object
554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 |
# File 'lib/eggshell/bundles/basics.rb', line 554 def format(tag, str) if tag == '{{' || tag == '`' cls = tag == '{{' ? 'normal' : 'backtick' return "<code class='#{cls}'>#{str}</code>" elsif tag == '%{' # @todo find a way to expand char map and handle unmapped strings at runtime buff = '' str.split(' ').each do |part| c = ESCAPE_MAP_HTML[part] buff += c || part end return buff end st = tag[0..1] args = parse_args(str.strip) akey = BH::BlockParams::ATTRIBUTES atts = {akey => {}} atts[akey].update(args.pop) tagname = nil tagopen = true text = args[0] if tag == '[~' link, text = args link = '' if !link text = '' if !text if text.strip == '' text = link end atts[akey]['href'] = link if link != '' tagname = 'a' elsif tag == '[!' link, alt = args link = '' if !link alt = '' if !alt atts[akey]['src'] = link if link != '' atts[akey]['alt'] = alt if alt != '' tagname = 'img' tagopen = false else tagname = TAG_MAP[tag] end if tagopen return "#{create_tag(tagname, atts)}#{text}</#{tagname}>" else return create_tag(tagname, atts, false) end end |