ppz 0.0.3 → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (39) hide show
  1. checksums.yaml +4 -4
  2. data/lib/doc/index.rb +9 -0
  3. data/lib/{model → doc/model}/abstract/model.rb +0 -0
  4. data/lib/{model → doc/model}/abstract/wrapper-model.rb +0 -0
  5. data/lib/{model → doc/model}/comment/container.rb +0 -0
  6. data/lib/{model → doc/model}/comment/item.rb +0 -0
  7. data/lib/{model → doc/model}/common/escape.rb +0 -0
  8. data/lib/{model → doc/model}/common/tag.rb +0 -0
  9. data/lib/doc/model/index.rb +17 -0
  10. data/lib/{model → doc/model}/list/item/abstract.rb +0 -0
  11. data/lib/{model → doc/model}/list/item/unordered.rb +0 -0
  12. data/lib/{model → doc/model}/list/wrapper/abstract.rb +0 -0
  13. data/lib/{model → doc/model}/list/wrapper/unordered.rb +0 -0
  14. data/lib/{model → doc/model}/p/index.rb +0 -0
  15. data/lib/{model → doc/model}/section/abstract.rb +0 -0
  16. data/lib/{model → doc/model}/section/leaf.rb +0 -0
  17. data/lib/{model → doc/model}/section/root.rb +0 -0
  18. data/lib/doc/model/special-block/container.rb +25 -0
  19. data/lib/{model → doc/model}/special-block/item.rb +1 -1
  20. data/lib/{parser/doc → doc/parser}/abstract.rb +1 -1
  21. data/lib/{parser/common/context/doc.rb → doc/parser/context.rb} +28 -1
  22. data/lib/{parser/doc → doc/parser}/file.rb +0 -0
  23. data/lib/{parser/doc → doc/parser}/string.rb +0 -0
  24. data/lib/folder/index.rb +9 -0
  25. data/lib/folder/model/abstract.rb +99 -0
  26. data/lib/folder/model/file/abstract.rb +27 -0
  27. data/lib/folder/model/file/other.rb +7 -0
  28. data/lib/folder/model/file/ppz.rb +15 -0
  29. data/lib/folder/model/folder.rb +104 -0
  30. data/lib/func/util.rb +1 -1
  31. data/lib/ppz.rb +2 -23
  32. metadata +32 -31
  33. data/asset/style/ppz.css +0 -90
  34. data/asset/style/ppz.styl +0 -82
  35. data/bin/common.rb +0 -43
  36. data/bin/ppz +0 -18
  37. data/lib/model/special-block/container.rb +0 -18
  38. data/lib/parser/common/context/abstract.rb +0 -30
  39. data/lib/parser/folder/index.rb +0 -7
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: db8561048fbdfb9e93187118596495ca8fad34f653d4ecc919ec1e3002c90b82
4
- data.tar.gz: d3620d7c86e55d1c31b34d1a4ae530ec7e3240782974493663ad6a72b07fefe1
3
+ metadata.gz: 5cc249a9892c07ef6b2f3325057c2d90574593435a90b4a097dd2d1f7d5a7d5b
4
+ data.tar.gz: f6573a7c9da1292fcf385a3bc0e23ca9d825219cb2d322316bd82395bde3604e
5
5
  SHA512:
6
- metadata.gz: ca3f12b9c1abdc2ed308e0690aece4480ad8e27ba33bdb5f2f6e187f1ddc7ae53e48459f2e8b50e698b492581a21053eb70e903f20016fcb47de6abce4ed0671
7
- data.tar.gz: 7f17a5aa3aff40111985b42e5544888d3f21c7295aa4d23ef81b56c5cb3193b4d3cca1d46062fcc88ea6023ef0e6492b7b9b5d05af32aefbc684fb93da0050ef
6
+ metadata.gz: c0a8ee4c7b4d6fe3c4bc8ae415d9a2b50cacc828723a0cf07c44fba5714468655cb803b44ba503ba58d70543acdd0d0cb7bfdebed4dab4890994a71d5a1e4a4a
7
+ data.tar.gz: 011012d0ed8c6e63e9fc1ccd6ce540e1098abaa45852cd19013b9bdf3edf8b4cf2a20d45da13b2ee5269ad4305529bf1466cd3f1005458b1573ecb4cef091e33
data/lib/doc/index.rb ADDED
@@ -0,0 +1,9 @@
1
+ module PPZ
2
+ # model
3
+ require_relative './model/index'
4
+ # parser
5
+ require_relative './parser/context'
6
+ require_relative './parser/abstract'
7
+ require_relative './parser/file'
8
+ require_relative './parser/string'
9
+ end
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
@@ -0,0 +1,17 @@
1
+ module PPZ
2
+ require_relative './abstract/model'
3
+ require_relative './abstract/wrapper-model'
4
+ require_relative './section/abstract'
5
+ require_relative './section/leaf'
6
+ require_relative './section/root'
7
+ require_relative './comment/container'
8
+ require_relative './comment/item'
9
+ require_relative './common/escape'
10
+ require_relative './list/wrapper/abstract'
11
+ require_relative './list/wrapper/unordered'
12
+ require_relative './list/item/abstract'
13
+ require_relative './list/item/unordered'
14
+ require_relative './p/index'
15
+ require_relative './special-block/container'
16
+ require_relative './special-block/item'
17
+ end
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
@@ -0,0 +1,25 @@
1
+ class PPZ::SpecialContainerModel < PPZ::AbstractWrapperModel
2
+ UpperClass = PPZ::AbstractSectionModel
3
+
4
+ REG_EXP = /^```( (.*))?$/
5
+ def self.from_line line
6
+ if REG_EXP.match line
7
+ if $2 && ($2.include? '```')
8
+ nil
9
+ else
10
+ PPZ::SpecialContainerModel.new $2
11
+ end
12
+ else
13
+ nil
14
+ end
15
+ end
16
+
17
+ def initialize name
18
+ @name = name
19
+ super()
20
+ end
21
+
22
+ def to_html
23
+ "<ol class=\"special-block-container #{@name}\">#{super}</ol>"
24
+ end
25
+ end
@@ -3,6 +3,6 @@ class PPZ::SpecialItemModel < PPZ::AbstractModel
3
3
  @line = line
4
4
  end
5
5
  def to_html
6
- "<div class=\"special-block-item\">#{@line}</div>"
6
+ "<li>#{@line}</li>"
7
7
  end
8
8
  end
@@ -2,7 +2,7 @@
2
2
 
3
3
  class PPZ::AbstractDocParser
4
4
  def initialize
5
- @context = PPZ::DocContext.new PPZ::RootSectionModel.new
5
+ @context = PPZ::ParserContext.new PPZ::RootSectionModel.new
6
6
  end
7
7
 
8
8
  def get_model
@@ -1,4 +1,11 @@
1
- class PPZ::DocContext < PPZ::AbstractContext
1
+ # 当前行,所处的上下文
2
+ # 比如 一级 section 下面的 ul 下的 第 n 个 ul
3
+
4
+ class PPZ::ParserContext
5
+ def initialize root
6
+ @stack = [root]
7
+ end
8
+
2
9
  def append target
3
10
  # ContainerClass: 容器类,如果上级不是,就造一个
4
11
  if(PPZ::Func::class_has_const? target, :ContainerClass) and (head.class != target.class::ContainerClass)
@@ -12,4 +19,24 @@ class PPZ::DocContext < PPZ::AbstractContext
12
19
  head.append target # 加入 model
13
20
  @stack.push target if target.is_a? PPZ::AbstractWrapperModel # 加入 stack
14
21
  end
22
+
23
+ def pop
24
+ @stack.pop
25
+ end
26
+
27
+ def head
28
+ @stack[-1]
29
+ end
30
+
31
+ def root
32
+ @stack[0]
33
+ end
34
+
35
+ private
36
+ def pop_to klass
37
+ loop do
38
+ break if head.is_a? klass
39
+ pop
40
+ end
41
+ end
15
42
  end
File without changes
File without changes
@@ -0,0 +1,9 @@
1
+ # 解析一个文件夹里的 .ppz 文件
2
+
3
+ module PPZ::Folder
4
+ require_relative './model/abstract'
5
+ require_relative './model/folder'
6
+ require_relative './model/file/abstract'
7
+ require_relative './model/file/other'
8
+ require_relative './model/file/ppz'
9
+ end
@@ -0,0 +1,99 @@
1
+ require 'pathname'
2
+
3
+ module PPZ::Folder
4
+ class AbstractModel
5
+ attr_reader :index, :name, :level
6
+ attr_accessor :prev_model, :next_model, :father_model
7
+
8
+ def initialize path, level
9
+ if path.is_a? String
10
+ path = Pathname path
11
+ elsif !(path.is_a? Pathname)
12
+ throw '文件夹的名字必须是 String 或 Pathname'
13
+ end
14
+ @path = path
15
+ @basename = path.basename.to_s
16
+ @level = level
17
+ end
18
+
19
+ def self.from_path path, level
20
+ level += 1
21
+ if Dir.exist? path
22
+ FolderModel.new path, level
23
+ elsif File.exist? path
24
+ AbstractFileModel.from_path path, level
25
+ else
26
+ throw path + '不存在?'
27
+ end
28
+ end
29
+
30
+ def relative_link target
31
+ relative_level = @level - target.level # relative_level 是“目标 model 比当前 level 高几级”
32
+
33
+ (if relative_level > 0
34
+ '../' * relative_level
35
+ elsif relative_level < 0
36
+ result = ''
37
+ father = target.father_model
38
+ (- relative_level).times do
39
+ result = father.name + '/' + result
40
+ father = father.father_model
41
+ end
42
+ result
43
+ else
44
+ ''
45
+ end) + target.name + '.html'
46
+ end
47
+
48
+ private
49
+ def to_html
50
+ get_head_html +
51
+ get_ancestor_html +
52
+ get_content_html +
53
+ get_nav_html +
54
+ get_js_html
55
+ end
56
+
57
+ def get_head_html
58
+ css_path = ('../' * @level) + '.ppz/asset/style/index.css'
59
+ %~<title>#{@name}</title><link rel="stylesheet" href="#{css_path}">~
60
+ end
61
+
62
+ def get_ancestor_html
63
+ list = []
64
+ father = self
65
+ loop do
66
+ break unless father.father_model
67
+ father = father.father_model
68
+ list.unshift father
69
+ end
70
+ %~<div class="ancestor-nav"><ul>#{
71
+ (list.collect do |node|
72
+ %`<li><a href="#{relative_link node}">#{node.name}</a></li>`
73
+ end
74
+ .join) + %`<li class="self">#{self.name}</li>`
75
+ }</ul></div>~
76
+ end
77
+
78
+ def get_nav_html
79
+ # prev_model nav_html
80
+ prev_model_html = ''
81
+ if @prev_model
82
+ prev_link = relative_link @prev_model
83
+ prev_model_html = "<li class=\"prev\"><a href=\"#{prev_link}\">#{@prev_model.name}</a></li>"
84
+ end
85
+ next_model_html = ''
86
+ if @next_model
87
+ next_link = relative_link @next_model
88
+ next_model_html = "<li class=\"next\"><a href=\"#{next_link}\">#{@next_model.name}</a></li>"
89
+ end
90
+
91
+ %~<ul class="interpage-nav">#{prev_model_html}#{next_model_html}</ul>~
92
+ end
93
+
94
+ def get_js_html
95
+ js_path = ('../' * @level) + '.ppz/asset/js/index.js'
96
+ %~<script type="module" src="#{js_path}"></script>~
97
+ end
98
+ end
99
+ end
@@ -0,0 +1,27 @@
1
+ module PPZ::Folder
2
+ class AbstractFileModel < AbstractModel
3
+ def self.from_path path, level
4
+ if (File.extname path) == '.ppz'
5
+ PPZFileModel.new path, level
6
+ else
7
+ OtherFileModel.new path, level
8
+ end
9
+ end
10
+
11
+ attr_reader :file_ext
12
+ def initialize path, level
13
+ super
14
+ temp_bn = @basename
15
+ if /^(\d+)_/.match temp_bn
16
+ @index = $1.to_i
17
+ temp_bn = temp_bn[($1.size + 1)..-1]
18
+ else
19
+ @index = Float::INFINITY
20
+ end
21
+
22
+ /(.*)(\.[^\.]+)$/.match temp_bn
23
+ @name = $1 || temp_bn
24
+ @file_ext = $2 || ''
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,7 @@
1
+ module PPZ::Folder
2
+ class OtherFileModel < AbstractFileModel
3
+ def _compile dir_out
4
+ FileUtils.cp @path, (dir_out + @basename)
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,15 @@
1
+ module PPZ::Folder
2
+ class PPZFileModel < AbstractFileModel
3
+ attr_accessor :left, :right
4
+
5
+ def _compile dir_out
6
+ PPZ::Func::write_to_file (dir_out + (@name + '.html')), to_html
7
+ end
8
+
9
+ private
10
+ def get_content_html
11
+ (PPZ::FileDocParser.new @path)
12
+ .get_model.to_html
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,104 @@
1
+ require 'pathname'
2
+
3
+ module PPZ::Folder
4
+ class FolderModel < AbstractModel
5
+ attr_reader :children
6
+
7
+ def initialize path, level
8
+ super
9
+ /^((\d+)_)?(.+)/.match @basename
10
+ @index = $2?($2.to_i):(Float::INFINITY)
11
+ @name = $3
12
+
13
+ @children = []
14
+ (Dir.children @path, encoding: 'utf-8').each do |child_name|
15
+ @children.push AbstractModel.from_path (@path + child_name), level
16
+ end
17
+ @children.sort! do |a, b|
18
+ a.index <=> b.index
19
+ end
20
+
21
+ # 设置上级 和 左右
22
+ left = right = nil
23
+ @children.each do |child|
24
+ child.father_model = self # 上级
25
+
26
+ next unless child.is_a? PPZFileModel
27
+ if left
28
+ left.right = child
29
+ child.left = left
30
+ end
31
+ left = child
32
+ end
33
+ end
34
+
35
+ def _compile out_dir # compile 是 _compile 的安全版本
36
+ out_file_pathname = out_dir + (@name + '.html')
37
+ PPZ::Func.write_to_file out_file_pathname, to_html
38
+
39
+ children_dir = out_dir + @name
40
+ Dir.mkdir children_dir
41
+ @children.each { |child| child._compile children_dir }
42
+ end
43
+
44
+ def compile out_dir
45
+ if out_dir.is_a? String
46
+ out_dir = Pathname out_dir
47
+ elsif !(out_dir.is_a? Pathname)
48
+ throw '输出文件夹的名字必须是 String 或 Pathname'
49
+ end
50
+
51
+ set_prev_and_next_page
52
+
53
+ unless Dir.exist? out_dir
54
+ throw "out_dir #{out_dir} 不存在"
55
+ end
56
+
57
+ _compile out_dir
58
+ end
59
+
60
+ def get_content_table_html root
61
+ %~<ul>#{
62
+ @children
63
+ .select do |child|
64
+ (child.class == FolderModel) || (child.file_ext == '.ppz')
65
+ end
66
+ .map do |child|
67
+ result = "<li><a href=\"./#{root.relative_link child}\">#{child.name}</a></li>"
68
+ if child.is_a? FolderModel
69
+ result += child.get_content_table_html root
70
+ end
71
+ result
72
+ end
73
+ .join
74
+ }</ul>~
75
+ end
76
+
77
+ # 设置页面的“上一篇、下一篇”
78
+ private
79
+ def set_prev_and_next_page
80
+ list = []
81
+ linearize_children self, list
82
+ list.inject do |pre, nex|
83
+ pre.next_model = nex
84
+ nex.prev_model = pre
85
+ nex
86
+ end
87
+ end
88
+
89
+ def linearize_children child, list
90
+ if child.is_a? PPZFileModel
91
+ list.push child
92
+ elsif child.is_a? FolderModel
93
+ list.push child
94
+ child.children.each do |cc|
95
+ linearize_children cc, list
96
+ end
97
+ end
98
+ end
99
+
100
+ def get_content_html
101
+ "<article>#{get_content_table_html self}</article>"
102
+ end
103
+ end
104
+ end
data/lib/func/util.rb CHANGED
@@ -4,7 +4,7 @@ class PPZ::Func
4
4
  if File.exist? filepath
5
5
  throw '文件已存在'
6
6
  end
7
- file = File.new filepath, 'w'
7
+ file = File.new filepath, mode: 'w:UTF-8'
8
8
  file.print data
9
9
  file.close
10
10
  end
data/lib/ppz.rb CHANGED
@@ -1,26 +1,5 @@
1
1
  module PPZ
2
2
  require_relative './func/util'
3
-
4
- require_relative './model/abstract/model'
5
- require_relative './model/abstract/wrapper-model'
6
- require_relative './model/section/abstract'
7
- require_relative './model/section/leaf'
8
- require_relative './model/section/root'
9
- require_relative './model/comment/container'
10
- require_relative './model/comment/item'
11
- require_relative './model/common/escape'
12
- require_relative './model/list/wrapper/abstract'
13
- require_relative './model/list/wrapper/unordered'
14
- require_relative './model/list/item/abstract'
15
- require_relative './model/list/item/unordered'
16
- require_relative './model/p/index'
17
- require_relative './model/special-block/container'
18
- require_relative './model/special-block/item'
19
-
20
- require_relative './parser/common/context/abstract'
21
- require_relative './parser/common/context/doc'
22
- require_relative './parser/doc/abstract'
23
- require_relative './parser/doc/file'
24
- require_relative './parser/doc/string'
25
-
3
+ require_relative './doc/index'
4
+ require_relative './folder/index'
26
5
  end
metadata CHANGED
@@ -1,49 +1,50 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ppz
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - wuse
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-02-05 00:00:00.000000000 Z
11
+ date: 2021-03-02 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description:
14
14
  email: 372301467@qq.com
15
- executables:
16
- - ppz
15
+ executables: []
17
16
  extensions: []
18
17
  extra_rdoc_files: []
19
18
  files:
20
- - asset/style/ppz.css
21
- - asset/style/ppz.styl
22
- - bin/common.rb
23
- - bin/ppz
19
+ - lib/doc/index.rb
20
+ - lib/doc/model/abstract/model.rb
21
+ - lib/doc/model/abstract/wrapper-model.rb
22
+ - lib/doc/model/comment/container.rb
23
+ - lib/doc/model/comment/item.rb
24
+ - lib/doc/model/common/escape.rb
25
+ - lib/doc/model/common/tag.rb
26
+ - lib/doc/model/index.rb
27
+ - lib/doc/model/list/item/abstract.rb
28
+ - lib/doc/model/list/item/unordered.rb
29
+ - lib/doc/model/list/wrapper/abstract.rb
30
+ - lib/doc/model/list/wrapper/unordered.rb
31
+ - lib/doc/model/p/index.rb
32
+ - lib/doc/model/section/abstract.rb
33
+ - lib/doc/model/section/leaf.rb
34
+ - lib/doc/model/section/root.rb
35
+ - lib/doc/model/special-block/container.rb
36
+ - lib/doc/model/special-block/item.rb
37
+ - lib/doc/parser/abstract.rb
38
+ - lib/doc/parser/context.rb
39
+ - lib/doc/parser/file.rb
40
+ - lib/doc/parser/string.rb
41
+ - lib/folder/index.rb
42
+ - lib/folder/model/abstract.rb
43
+ - lib/folder/model/file/abstract.rb
44
+ - lib/folder/model/file/other.rb
45
+ - lib/folder/model/file/ppz.rb
46
+ - lib/folder/model/folder.rb
24
47
  - lib/func/util.rb
25
- - lib/model/abstract/model.rb
26
- - lib/model/abstract/wrapper-model.rb
27
- - lib/model/comment/container.rb
28
- - lib/model/comment/item.rb
29
- - lib/model/common/escape.rb
30
- - lib/model/common/tag.rb
31
- - lib/model/list/item/abstract.rb
32
- - lib/model/list/item/unordered.rb
33
- - lib/model/list/wrapper/abstract.rb
34
- - lib/model/list/wrapper/unordered.rb
35
- - lib/model/p/index.rb
36
- - lib/model/section/abstract.rb
37
- - lib/model/section/leaf.rb
38
- - lib/model/section/root.rb
39
- - lib/model/special-block/container.rb
40
- - lib/model/special-block/item.rb
41
- - lib/parser/common/context/abstract.rb
42
- - lib/parser/common/context/doc.rb
43
- - lib/parser/doc/abstract.rb
44
- - lib/parser/doc/file.rb
45
- - lib/parser/doc/string.rb
46
- - lib/parser/folder/index.rb
47
48
  - lib/ppz.rb
48
49
  homepage: https://github.com/daGaiGuanYu/ppz
49
50
  licenses:
@@ -67,5 +68,5 @@ requirements: []
67
68
  rubygems_version: 3.1.4
68
69
  signing_key:
69
70
  specification_version: 4
70
- summary: 写作
71
+ summary: compile ppz to html
71
72
  test_files: []
data/asset/style/ppz.css DELETED
@@ -1,90 +0,0 @@
1
- html {
2
- line-height: 1.5;
3
- }
4
- body,
5
- div,
6
- p,
7
- aside {
8
- box-sizing: border-box;
9
- }
10
- body {
11
- margin: 0;
12
- padding: 0;
13
- position: relative;
14
- }
15
- aside {
16
- overflow-y: auto;
17
- padding: 2rem 1rem;
18
- position: fixed;
19
- top: 0;
20
- left: 0;
21
- width: 188px;
22
- height: 100vh;
23
- }
24
- aside ul {
25
- margin: 0 0 0 1rem;
26
- padding: 0;
27
- list-style: none;
28
- }
29
- aside a {
30
- width: 100%;
31
- overflow: hidden;
32
- text-overflow: ellipsis;
33
- white-space: nowrap;
34
- }
35
- article {
36
- margin-left: 188px;
37
- padding: 1px 1rem;
38
- }
39
- h1 {
40
- font-size: 2rem;
41
- }
42
- h2 {
43
- font-size: 1.3rem;
44
- }
45
- h3 {
46
- font-size: 1.1rem;
47
- opacity: 0.9;
48
- }
49
- h1::before,
50
- h2::before,
51
- h3::before {
52
- content: '# ';
53
- opacity: 0.3;
54
- font-size: 1rem;
55
- }
56
- .comment-container {
57
- margin: 1rem 0;
58
- padding: 1rem 1.6rem;
59
- background: rgba(0,0,0,0.2);
60
- font-size: 0.9rem;
61
- border-radius: 4px;
62
- }
63
- .comment-item {
64
- opacity: 0.8;
65
- }
66
- .special-block-container {
67
- background: #141c22;
68
- overflow: auto;
69
- border-radius: 4px;
70
- color: #eee;
71
- font-family: monospace;
72
- white-space: pre;
73
- margin: 1rem 0;
74
- padding: 1rem;
75
- counter-reset: line-index;
76
- }
77
- .special-block-item::before {
78
- counter-increment: line-index;
79
- content: counter(line-index) " | ";
80
- opacity: 0.3;
81
- }
82
- .special-block-item:hover::before {
83
- opacity: 0.8;
84
- }
85
- .special-txt {
86
- background: rgba(27,31,35,0.05);
87
- border-radius: 4px;
88
- font-size: 0.9em;
89
- padding: 2px 4px;
90
- }
data/asset/style/ppz.styl DELETED
@@ -1,82 +0,0 @@
1
- html
2
- line-height 1.5
3
- body, div, p, aside
4
- box-sizing border-box
5
-
6
- body
7
- margin 0
8
- padding 0
9
- position relative
10
-
11
- aside
12
- overflow-y auto
13
- padding: 2rem 1rem;
14
-
15
- position fixed
16
- top 0
17
- left 0
18
- width 188px
19
- height 100vh
20
-
21
- ul
22
- margin 0 0 0 1rem
23
- padding 0
24
- list-style none
25
- a
26
- width 100%
27
- overflow hidden
28
- text-overflow ellipsis
29
- white-space nowrap
30
-
31
- article
32
- margin-left: 188px
33
- padding: 1px 1rem
34
- h1
35
- font-size 2rem
36
- h2
37
- font-size 1.3rem
38
- h3
39
- font-size 1.1rem
40
- opacity 0.9
41
-
42
- h1, h2, h3
43
- &::before
44
- content '# '
45
- opacity 0.3
46
- font-size 1rem
47
-
48
- .comment-container
49
- margin 1rem 0
50
- padding 1rem 1.6rem
51
- background rgba(0, 0, 0, 0.2)
52
- font-size 0.9rem
53
- border-radius 4px
54
- .comment-item
55
- opacity 0.8
56
-
57
- .special-block-container
58
- background #141c22
59
- overflow auto
60
- border-radius 4px
61
- color #eeeeee
62
-
63
- font-family monospace
64
- white-space pre
65
-
66
- margin 1rem 0
67
- padding 1rem
68
-
69
- counter-reset line-index
70
- .special-block-item
71
- &::before
72
- counter-increment line-index
73
- content counter(line-index) " | "
74
- opacity 0.3
75
- &:hover::before
76
- opacity 0.8
77
-
78
- .special-txt
79
- background rgba(27, 31, 35, 0.05)
80
- border-radius 4px
81
- font-size 0.9em
82
- padding 2px 4px
data/bin/common.rb DELETED
@@ -1,43 +0,0 @@
1
- require 'pathname'
2
-
3
- module PPZMain
4
- CURRENT_PATH = File.dirname __FILE__
5
- WORK_DIRECTORY = Pathname Dir.pwd
6
- CSS_FILE_PATH = (Pathname CURRENT_PATH) + '../asset/style/ppz.css'
7
-
8
- class Util
9
- class << self
10
- def get_in_and_out
11
- target_in, target_out = ARGV
12
-
13
- # + 输入文件
14
- abort '要编译哪那个文件?请告诉我' unless target_in # 检查参数存在
15
- target_in = (WORK_DIRECTORY + target_in).to_s # 绝对路径
16
- unless File.exist? target_in # 不存在的话,看看加上 .ppz 后是否存在
17
- target_in += '.ppz'
18
- abort target_in[0..-5] + ' 不存在' unless File.exist? target_in # 还不存在的话,就说明是写错了
19
- end
20
- abort '尚未支持编译文件夹' if File.directory? target_in
21
-
22
- # + 输出文件
23
- unless target_out
24
- # 从输入文件获取文件名
25
- target_out = ((/(.*).ppz$/.match target_in)?$1:target_in) + '.pp'
26
- end
27
- target_out = WORK_DIRECTORY + target_out
28
- # ++ 检查上级文件夹是否存在
29
- upper_dir = (target_out + '..').to_s
30
- abort upper_dir + ' 目录不存在' unless Dir.exist? upper_dir
31
- # ++ 检查文件夹:有则检查里面有没有文件;无则创建文件夹
32
- target_out = target_out.to_s
33
- if Dir.exist? target_out
34
- abort target_out + ' 不是一个空文件夹' unless (Dir.children target_out).size == 0
35
- else
36
- Dir.mkdir target_out
37
- end
38
-
39
- [target_in, target_out]
40
- end
41
- end
42
- end
43
- end
data/bin/ppz DELETED
@@ -1,18 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require_relative '../lib/ppz'
4
- require_relative './common'
5
- require 'fileutils'
6
- require 'pathname'
7
-
8
- target_in, target_out = PPZMain::Util.get_in_and_out
9
-
10
- target_out = Pathname target_out
11
- output_html_path = target_out + 'index.html'
12
- output_css_path = target_out + 'index.css'
13
-
14
- parser = PPZ::FileDocParser.new target_in
15
- model = parser.get_model
16
- output_html = '<link rel="stylesheet" href="./index.css"/>' + model.to_html
17
- PPZ::Func::write_to_file output_html_path.to_s, output_html
18
- FileUtils.cp PPZMain::CSS_FILE_PATH, output_css_path
@@ -1,18 +0,0 @@
1
- class PPZ::SpecialContainerModel < PPZ::AbstractWrapperModel
2
- UpperClass = PPZ::AbstractSectionModel
3
-
4
- REG_EXP = /^```( (.*))?/
5
- def self.from_line line
6
- return nil unless REG_EXP.match(line)
7
- PPZ::SpecialContainerModel.new $2
8
- end
9
-
10
- def initialize name
11
- @name = name
12
- super()
13
- end
14
-
15
- def to_html
16
- "<div class=\"special-block-container #{@name}\">#{super}</div>"
17
- end
18
- end
@@ -1,30 +0,0 @@
1
- # 当前行,所处的上下文
2
- # 比如 一级 section 下面的 ul 下的 第 n 个 ul
3
-
4
- class PPZ::AbstractContext
5
- def initialize root
6
- @stack = [root]
7
- end
8
-
9
- # def append # 交给子类实现
10
-
11
- def pop
12
- @stack.pop
13
- end
14
-
15
- def head
16
- @stack[-1]
17
- end
18
-
19
- def root
20
- @stack[0]
21
- end
22
-
23
- private
24
- def pop_to klass
25
- loop do
26
- break if head.is_a? klass
27
- pop
28
- end
29
- end
30
- end
@@ -1,7 +0,0 @@
1
- # 解析一个文件夹里的 .ppz 文件
2
-
3
- class FolderParser
4
- def initialize
5
- @context = Context.new
6
- end
7
- end