From 88029687c9ad611c1f2c70f789347605dc2041c3 Mon Sep 17 00:00:00 2001 From: Ralph Amissah Date: Fri, 30 Apr 2010 19:52:57 -0400 Subject: emphasis display and plaintext line wrap configurable in document or sis * markup for *{emphasis}* configurable as being displayed either bold or italics, the default is that emphasis output is in bold so there is no at present unless configured, either in sisurc.yml (default: emphasis: 'italics'), or the markup source document header @make: :emphasis: 'it [requested] * plaintext, wrap width configurable between 20 to 200 characters, the default width being 78, configuration eithe rin sisurc.yml (default: t 78), or the markup source document header (@make: :plaintext_wrap: 78) --- lib/sisu/v2/constants.rb | 2 ++ lib/sisu/v2/dal_syntax.rb | 9 +++++--- lib/sisu/v2/param.rb | 13 ++++++++++++ lib/sisu/v2/plaintext.rb | 53 +++++++++++++++++++++++++++-------------------- lib/sisu/v2/sysenv.rb | 15 +++++++++++--- 5 files changed, 64 insertions(+), 28 deletions(-) diff --git a/lib/sisu/v2/constants.rb b/lib/sisu/v2/constants.rb index 83914038..7fc3b056 100644 --- a/lib/sisu/v2/constants.rb +++ b/lib/sisu/v2/constants.rb @@ -114,6 +114,8 @@ Dx[:rel_o]='‹'; Dx[:rel_c]='›' Tex[:backslash]="\\\\" Tex[:backslash]="\\\\" Tex[:tilde]='\\\\\\~' +#Px[:emphasis_o]= '*'; Px[:emphasis_c]= '*' +#Px[:bold_o]= '!'; Px[:bold_c]= '!' Px[:bold_o]= '*'; Px[:bold_c]= '*' Px[:italics_o]= '/'; Px[:italics_c]= '/' Px[:underscore_o]= '_'; Px[:underscore_c]= '_' diff --git a/lib/sisu/v2/dal_syntax.rb b/lib/sisu/v2/dal_syntax.rb index dd83ef3b..59620856 100644 --- a/lib/sisu/v2/dal_syntax.rb +++ b/lib/sisu/v2/dal_syntax.rb @@ -70,11 +70,14 @@ module SiSU_Syntax url_and_stub=SiSU_Env::Info_env.new.url @output_url="#{url_and_stub.remote}" @env=SiSU_Env::Info_env.new - @emph=(@env.markup_emphasis =~/italics/) \ + emph_italics=((@env.markup_emphasis =~/italics/) \ + || (defined? @md.make.emphasis && @md.make.emphasis =~/italics/)) \ + ? true : false + @emph=emph_italics \ ? ({:o =>Mx[:fa_italics_o], :c =>Mx[:fa_italics_c] }) \ : ({:o =>Mx[:fa_bold_o], :c =>Mx[:fa_bold_c] }) @http_m=%r{\{.+?\}https?://\S+|https?:\S+|\.\.\/\S+|\S+?\.png\b|[*]~\S+|^#{Mx[:meta_o]}.+|#{Mx[:gr_o]}(?:code|group|alt|verse)(?:-end)?#{Mx[:gr_c]}|#{Mx[:fa_o]}:br#{Mx[:fa_c]}} - @manmkp_ital=(@env.markup_emphasis =~/italics/) \ + @manmkp_ital=emph_italics \ ? '[i/*]\\{.+?\\}[i/*]' \ : '[i/]\\{.+?\\}[i/]' tail_m_ital=%q{(?:\s|[.,;:?!'")]|~\^|~\\\{\s|$)} @@ -89,7 +92,7 @@ module SiSU_Syntax elsif defined? @vz.markup_make_italic[:str] /#{@http_m}|#{bold_line}|#{@manmkp_ital}#{tail_m_ital}|#{@vz.markup_make_italic[:str]}#{tail_m_ital}|\S+|\n/ end - @manmkp_bold=(@env.markup_emphasis =~/italics/) \ + @manmkp_bold=emph_italics \ ? '^!_\s.+?(?:\n|$)|[!b]\\{.+?\\}[*!b]|[*!][a-zA-Z0-9\-_]+[!]' \ : '^!_\s.+?(?:\n|$)|[*!b]\\{.+?\\}[*!b]|[*!][a-zA-Z0-9\-_]+[*!]' @line_scan_bold=if (defined? @md.make.bold[:str] \ diff --git a/lib/sisu/v2/param.rb b/lib/sisu/v2/param.rb index a59ac8ff..fc24501a 100644 --- a/lib/sisu/v2/param.rb +++ b/lib/sisu/v2/param.rb @@ -657,6 +657,19 @@ module SiSU_Param y=((x =~/i/) ? (/#{rgx}/i) : (/#{rgx}/)) { :str =>'\b(?:' + m + ')\b', :regx => y } end + def emphasis + (@h['emphasis'] =~/italics?/) \ + ? 'italics' \ + : 'bold' + end + def plaintext_wrap + if @h['plaintext_wrap'].to_s =~/\d\d+/ \ + and @h['plaintext_wrap'].to_i > 19 \ + and @h['plaintext_wrap'].to_i < 201 + @h['plaintext_wrap'].to_i + else nil + end + end def skin @h['skin'] end diff --git a/lib/sisu/v2/plaintext.rb b/lib/sisu/v2/plaintext.rb index 851da3f8..c69490ab 100644 --- a/lib/sisu/v2/plaintext.rb +++ b/lib/sisu/v2/plaintext.rb @@ -79,20 +79,29 @@ module SiSU_Plaintext end def read begin - @md=SiSU_Param::Parameters.new(@opt).get - @env=SiSU_Env::Info_env.new(@opt.fns) - path=@env.path.output_tell - tool=if @opt.cmd =~/[MVv]/; "#{@env.program.text_editor} #{path}/#{@md.fnb}/#{@md.fn[:plain]}" + md=SiSU_Param::Parameters.new(@opt).get + env=SiSU_Env::Info_env.new(@opt.fns) + path=env.path.output_tell + tool=if @opt.cmd =~/[MVv]/; "#{env.program.text_editor} #{path}/#{md.fnb}/#{md.fn[:plain]}" else '' end tell=SiSU_Screen::Ansi.new(@opt.cmd,'Plaintext',tool) tell.green_hi_blue unless @opt.cmd =~/q/ - tell=SiSU_Screen::Ansi.new(@opt.cmd,@opt.fns,"#{@env.path.output_tell}/#{@md.fnb}/#{@md.fn[:plain]}") + tell=SiSU_Screen::Ansi.new(@opt.cmd,@opt.fns,"#{env.path.output_tell}/#{md.fnb}/#{md.fn[:plain]}") tell.flow if @opt.cmd =~/[MV]/ my_make=SiSU_Env::Create_file.new(@opt.cmd,@opt.fns) - @dal_array=SiSU_DAL::Source.new(@opt).get # dal file drawn here - SiSU_Plaintext::Source::Scroll.new(@dal_array,@md).songsheet - SiSU_Env::Info_skin.new(@md).select #watch + dal_array=SiSU_DAL::Source.new(@opt).get # dal file drawn here + wrap_width=if defined? md.make.plaintext_wrap \ + and md.make.plaintext_wrap + md.make.plaintext_wrap + elsif defined? env.plaintext_wrap \ + and env.plaintext_wrap + env.plaintext_wrap + else 78 + end + #wrap_width=(defined? md.make.plaintext_wrap) ? md.make.plaintext_wrap : 78 + SiSU_Plaintext::Source::Scroll.new(dal_array,md,wrap_width).songsheet + SiSU_Env::Info_skin.new(md).select #watch rescue; SiSU_Errors::Info_error.new($!,$@,@opt.cmd,@opt.fns).error ensure end @@ -103,8 +112,8 @@ module SiSU_Plaintext require "#{SiSU_lib}/shared_txt" # shared_txt.rb include SiSU_text_utils @@endnotes={ :para=>[],:end=>[] } - def initialize(data,md) - @data,@md=data,md + def initialize(data,md,wrap_width) + @data,@md,@wrap_width=data,md,wrap_width @brace_url=SiSU_Viz::Skin.new.url_decoration @vz=SiSU_Env::Get_init.instance.skin @tab="\t" @@ -141,9 +150,9 @@ module SiSU_Plaintext end notes=@n.flatten notes.each do |e| - util=if e.to_s =~/^\[[\d*+]+\]:/; SiSU_text_utils::Wrap.new(e.to_s,78,4,1) - else SiSU_text_utils::Wrap.new(e.to_s,78,1,1) - end + util=(e.to_s =~/^\[[\d*+]+\]:/) \ + ? (SiSU_text_utils::Wrap.new(e.to_s,@wrap_width,4,1)) \ + : (SiSU_text_utils::Wrap.new(e.to_s,@wrap_width,1,1)) wrap=util.line_wrap if wrap =~ /^\s*[\d*+]+\s+.+?\s*\Z/m wrap.gsub!(/^(\s*)([\d*+]+)\s+(.+?)\s*\Z/m, < 78 + times=@wrap_width if times > @wrap_width @plaintext[:body] << case lv when 1; wrapped.upcase << @br << Px[:lv1]*times << @br when 2; wrapped.upcase << @br << Px[:lv2]*times << @br @@ -356,9 +365,9 @@ WOK content << plaintext[:head] content << plaintext[:body] content << @@endnotes[:end] if @@endnotes_ - content << "#{@br}#{divider*78}#{@br}" + content << "#{@br}#{divider*@wrap_width}#{@br}" content << plaintext[:metadata] - content << "#{@br}#{divider*78}#{@br}" if @md.stmp =~/\w+/ #not used? + content << "#{@br}#{divider*@wrap_width}#{@br}" if @md.stmp =~/\w+/ #not used? content << plaintext[:owner_details] if @md.stmp =~/\w+/ #not used? content << plaintext[:tail] Output.new(content,@md).plaintext diff --git a/lib/sisu/v2/sysenv.rb b/lib/sisu/v2/sysenv.rb index c5bc63c2..4a2f7ee0 100644 --- a/lib/sisu/v2/sysenv.rb +++ b/lib/sisu/v2/sysenv.rb @@ -876,12 +876,21 @@ module SiSU_Env : (defaults[:concord_max]) end def markup_emphasis - ((defined? @rc['markup']['emphasis']) \ - && @rc['markup']['emphasis'] \ - && (@rc['markup']['emphasis']=~/italic/)) \ + ((defined? @rc['default']['emphasis']) \ + && @rc['default']['emphasis'] \ + && (@rc['default']['emphasis']=~/italic/)) \ ? 'italics' \ : 'bold' end + def plaintext_wrap + ((defined? @rc['default']['text_wrap']) \ + && (@rc['default']['text_wrap']) \ + && (@rc['default']['text_wrap'].to_s=~/\d\d+/) \ + && (@rc['default']['text_wrap'].to_i > 19) \ + && (@rc['default']['text_wrap'].to_i < 201)) \ + ? @rc['default']['text_wrap'].to_i \ + : 78 + end def current_document @@current_document||=Dir.pwd @@current_document -- cgit v1.2.3