Sha256: 7e4705516686993f84a69e114df8282773e79a68b3753eef7354b59b6eacb697
Contents?: true
Size: 1.49 KB
Versions: 3
Compression:
Stored size: 1.49 KB
Contents
# -*- encoding: utf-8 -*- module ArtiMark module CommandLexer def escape_html(string) string.to_s.gsub("&", "&"). gsub("<", "<"). gsub(">", ">"). gsub('"', """) end def class_string(cls_array) if cls_array.size == 0 '' else " class='#{cls_array.join(' ')}'" end end def class_array(cls_part) cls_array = [] if !cls_part.nil? && cls_part.size > 0 cls_array = cls_part[1..-1].split('.') end cls_array end def param_array(param_part) r = [] if !param_part.nil? && param_part.size > 0 r = param_part.split(',') end r end def lex_line_command(line) line =~ /^([\w\*;]+?)((?:\.[A-Za-z0-9_\-]+?)*)(?:\((.+?)\))?\s*:(.*?)$/ return { :cmd => $1, :cls => class_array($2), :params => param_array($3), :text => $4 } end def lex_block_command(line) line =~ /^(\w+?)((?:\.[A-Za-z0-9_\-]+?)*)(?:\((.+?)\))?\s*{\s*$/ return { :cmd => $1, :cls => class_array($2), :params => param_array($3)} end def replace_inline_commands(line, syntax, context) line.gsub(/\[(\w+?)((?:\.[A-Za-z0-9_\-]+?)*)(?:\((.+?)\))?\s*{(.*?)}\]/) { |matched| lexed = {:cmd => $1, :cls => class_array($2), :params => param_array($3), :text => $4 } if !lexed[:cmd].nil? syntax.inline_handler.send(lexed[:cmd], lexed, context) else matched end } end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
arti_mark-0.0.1.beta2 | lib/arti_mark/command_lexer.rb |
arti_mark-0.0.1.beta1 | lib/arti_mark/command_lexer.rb |
arti_mark-0.0.1.beta0 | lib/arti_mark/command_lexer.rb |