Class: PPZ::AbstractModel

Inherits:
Object
  • Object
show all
Defined in:
lib/doc/model/abstract/model.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#father_modelObject

Returns the value of attribute father_model.



3
4
5
# File 'lib/doc/model/abstract/model.rb', line 3

def father_model
  @father_model
end

#indexObject

左右兄弟 model



2
3
4
# File 'lib/doc/model/abstract/model.rb', line 2

def index
  @index
end

#left_modelObject

左右兄弟 model



2
3
4
# File 'lib/doc/model/abstract/model.rb', line 2

def left_model
  @left_model
end

#right_modelObject

左右兄弟 model



2
3
4
# File 'lib/doc/model/abstract/model.rb', line 2

def right_model
  @right_model
end

Class Method Details

.from_line(line) ⇒ Object

静态方法,从“输入行”里实例化一个 model



5
6
7
8
# File 'lib/doc/model/abstract/model.rb', line 5

def self.from_line line # 静态方法,从“输入行”里实例化一个 model
  return nil unless self::REG_EXP.match(line)
  self.new $1
end

Instance Method Details

#transform_inline_element(str) ⇒ Object

加粗、斜体、链接等



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/doc/model/abstract/model.rb', line 11

def transform_inline_element str
  str = str + ''
  # 因为加粗、斜体等,会生成 html 代码,为了不使“用户原本输入的 html”和“生成的 html”冲突,因此先把“用户输入的 html 转义
  PPZ::Escape.html_char! str
  
  # 变粗等,使用特殊字符比如 *,来标识
  # 但这会使用户想输入 * 时,形成歧义
  # 因此,用户向输入 *(而不是变斜时),可以输入 \*

  # 所以此流程
  # 先把 * 等特殊字符转义(\* -> 某种形式)
  # 再识别哪些变斜,哪些变粗
  # 再把用户原来想输入的 * 放到字符串里(某种形式 -> *)

  PPZ::Escape.ppz_char! str # 把用户输入的 \* 转义 => 剩下的 *** 就肯定是 斜体加粗 了

  # + 斜体和加粗
  str.gsub! /\*\*\*(.+)\*\*\*/, '<b><i>\1</i></b>'
  # + 加粗
  str.gsub! /\*\*(.+)\*\*/, '<b>\1</b>'
  # + 斜体
  str.gsub! /\*(.+)\*/, '<i>\1</i>'
  # + 行内块
  str.gsub! /```([^(```)]+)```/, '<span class="special-txt">\1</span>'
  # + 图片 先图片后链接
  str.gsub! /!\[([^\]]*)\]\(([^\)]+)\)/, '<img title="\1" src="\2" />'
  # + 链接 先图片后链接
  str.gsub! /\[([^\]]+)\]\(([^\)]+)\)/, '<a href="\2" title="\2">\1</a>'
  
  PPZ::Escape.transform_to_real! str
end