Class: Yast::RichTextClass
- Inherits:
-
Module
- Object
- Module
- Yast::RichTextClass
- Defined in:
- ../../src/modules/RichText.rb
Instance Method Summary (collapse)
-
- (Symbol) DetectRichText(file)
Parse provided text and see if it contains richtext.
- - (Object) DropWS(text)
- - (Object) main
-
- (Object) Rich2Plain(richtext)
Convert a richtext string into a formatted plain text.
Instance Method Details
- (Symbol) DetectRichText(file)
Parse provided text and see if it contains richtext
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 |
# File '../../src/modules/RichText.rb', line 121 def DetectRichText(file) text = "" if Ops.greater_than(SCR.Read(path(".target.size"), file), 0) text = Convert.to_string(SCR.Read(path(".target.string"), file)) else return :error end return :empty if text == "" if Builtins.regexpmatch(text, "</.*>") return :richtext else return :plaintext end end |
- (Object) DropWS(text)
41 42 43 44 |
# File '../../src/modules/RichText.rb', line 41 def DropWS(text) filteredlist = Builtins.splitstring(text, "\n\t") String.CutBlanks(Builtins.mergestring(filteredlist, " ")) end |
- (Object) main
36 37 38 39 |
# File '../../src/modules/RichText.rb', line 36 def main textdomain "base" Yast.import "String" end |
- (Object) Rich2Plain(richtext)
Convert a richtext string into a formatted plain text.
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 |
# File '../../src/modules/RichText.rb', line 49 def Rich2Plain(richtext) Builtins.y2debug("richtext=%1", richtext) lparts = Builtins.splitstring(DropWS(richtext), "<") Builtins.y2debug("lparts=%1", lparts) # Am I in <LI>? inli = false # Indentation level indents = 0 result = "" Builtins.foreach(lparts) do |lpart| s = Builtins.find(lpart, ">") tag = Builtins.tolower(Builtins.substring(lpart, 0, s)) # *** Handle tags **** # BR if tag == "br" result = Ops.add(result, "\n") # P elsif tag == "p" result = Ops.add(result, "\n") # UL elsif tag == "ul" inli = true indents = Ops.add(indents, 1) # /UL elsif tag == "/ul" result = Ops.add(result, "\n") if inli && indents == 1 indents = Ops.subtract(indents, 1) inli = false # LI elsif tag == "li" result = Ops.add(result, "\n") if inli inli = true # /LI elsif tag == "/li" inli = false result = Ops.add(result, "\n") end # *** Add the text **** if s != -1 lpart = String.CutBlanks(Builtins.substring(lpart, Ops.add(s, 1))) end next if Builtins.regexpmatch(lpart, "^[ \n\t]*$") next if lpart == " " if lpart != "" && inli i = 1 while Ops.less_than(i, indents) result = Ops.add(result, " ") i = Ops.add(i, 1) end lpart = Ops.add("* ", lpart) end # result = result + "[" + lpart + "]"; result = Ops.add(result, lpart) end result = String.CutBlanks(result) if Ops.greater_than(Builtins.size(result), 0) && Builtins.substring(result, Ops.subtract(Builtins.size(result), 1)) != "\n" result = Ops.add(result, "\n") end Builtins.y2debug(result) result end |