jotdown 0.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.
- checksums.yaml +7 -0
- data/CHANGELOG.md +5 -0
- data/LICENSE +22 -0
- data/README.md +25 -0
- data/Rakefile +4 -0
- data/jotdown.gemspec +39 -0
- data/lib/.DS_Store +0 -0
- data/lib/hello.html +17 -0
- data/lib/hello.jd +2 -0
- data/lib/jotdown/version.rb +5 -0
- data/lib/jotdown.rb +152 -0
- metadata +55 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 1950f356fec531c46908687fd64d03250ecf34323786c5c4e58a31d3d142d02c
|
|
4
|
+
data.tar.gz: 3eb00f025c370322aacf43bbc20d513d640cb9e1dfd2fef80c277a763f874aa8
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 8ed63f4ce12660022e3ba122f5f98350279e75bf9c96b5165fe267eaa9cfbd153633ffb0492cf2afe35b506b50741a5a64301464e8b30ff8463dcc8358a258ab
|
|
7
|
+
data.tar.gz: 3266af2d9dea13619a13bc41449688472b449ec1e62691cc728a010ab85985291b0642572d3a09dcf87c179eb746e8d12440f19d5e0038fe7cdd569d31d08954
|
data/CHANGELOG.md
ADDED
data/LICENSE
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (C) 2012-present Dan Allen, Sarah White, Ryan Waldron, and the
|
|
4
|
+
individual contributors to Asciidoctor.
|
|
5
|
+
|
|
6
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
8
|
+
in the Software without restriction, including without limitation the rights
|
|
9
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
11
|
+
furnished to do so, subject to the following conditions:
|
|
12
|
+
|
|
13
|
+
The above copyright notice and this permission notice shall be included in
|
|
14
|
+
all copies or substantial portions of the Software.
|
|
15
|
+
|
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
22
|
+
THE SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# Jotdown
|
|
2
|
+
|
|
3
|
+
jotdown is a short markdown with suport fot rtl and so on.
|
|
4
|
+
jotdown gem that allow you to easily generate a html file from jd files.
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
To install Jotdown with RubyGems:
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
$ gem install jotdown
|
|
13
|
+
```
|
|
14
|
+
## Usage
|
|
15
|
+
|
|
16
|
+
If the Jotdown gem installed successfully, run the following in your terminal:
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
$ ruby jotdown sample.jd another_file.jd
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## License
|
|
23
|
+
|
|
24
|
+
Jotdown is released under the MIT license.
|
|
25
|
+
|
data/Rakefile
ADDED
data/jotdown.gemspec
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "lib/jotdown/version"
|
|
4
|
+
|
|
5
|
+
Gem::Specification.new do |spec|
|
|
6
|
+
spec.name = "jotdown"
|
|
7
|
+
spec.version = Jotdown::VERSION
|
|
8
|
+
spec.authors = ["Hamidreza Safari"]
|
|
9
|
+
spec.email = ["hamidrezasafari@hotmail.com"]
|
|
10
|
+
|
|
11
|
+
spec.summary = "jotdown is a short markdown"
|
|
12
|
+
spec.description = "jotdown is a short markdown"
|
|
13
|
+
spec.homepage = "https://github.com/HamidrezaSafari/Jotdown"
|
|
14
|
+
spec.required_ruby_version = ">= 3.0.0"
|
|
15
|
+
|
|
16
|
+
# spec.metadata["allowed_push_host"] = "https://github.com/HamidrezaSafari/Jotdown"
|
|
17
|
+
|
|
18
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
|
19
|
+
spec.metadata["source_code_uri"] = "https://github.com/HamidrezaSafari/Jotdown"
|
|
20
|
+
spec.metadata["changelog_uri"] = "https://github.com/HamidrezaSafari/Jotdown"
|
|
21
|
+
|
|
22
|
+
# Specify which files should be added to the gem when it is released.
|
|
23
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
|
24
|
+
spec.files = Dir.chdir(__dir__) do
|
|
25
|
+
`git ls-files -z`.split("\x0").reject do |f|
|
|
26
|
+
(File.expand_path(f) == __FILE__) ||
|
|
27
|
+
f.start_with?(*%w[bin/ test/ spec/ features/ .git appveyor Gemfile])
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
spec.bindir = "exe"
|
|
31
|
+
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
|
32
|
+
spec.require_paths = ["lib"]
|
|
33
|
+
|
|
34
|
+
# Uncomment to register a new dependency of your gem
|
|
35
|
+
# spec.add_dependency "example-gem", "~> 1.0"
|
|
36
|
+
|
|
37
|
+
# For more information and examples about making a new gem, check out our
|
|
38
|
+
# guide at: https://bundler.io/guides/creating_gem.html
|
|
39
|
+
end
|
data/lib/.DS_Store
ADDED
|
Binary file
|
data/lib/hello.html
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="utf-8">
|
|
5
|
+
<meta http-equiv="x-ua-compatible" content="ie=edge">
|
|
6
|
+
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
|
|
7
|
+
<title>index</title>
|
|
8
|
+
<style>
|
|
9
|
+
#tag_0
|
|
10
|
+
,#tag_1
|
|
11
|
+
|
|
12
|
+
</style>
|
|
13
|
+
</head>
|
|
14
|
+
<body>
|
|
15
|
+
<h1 id="tag_0">hello world</h1> <p id="tag_1">paragraph text</p>
|
|
16
|
+
</body>
|
|
17
|
+
</html>
|
data/lib/hello.jd
ADDED
data/lib/jotdown.rb
ADDED
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "jotdown/version"
|
|
4
|
+
|
|
5
|
+
module Jotdown
|
|
6
|
+
class Error < StandardError; end
|
|
7
|
+
class Document
|
|
8
|
+
attr_accessor :next_p, :tokens
|
|
9
|
+
|
|
10
|
+
def initialize(file)
|
|
11
|
+
@tokens = []
|
|
12
|
+
@source = File.read(file).split("\n")
|
|
13
|
+
@file_name = file.sub(".jd",".html")
|
|
14
|
+
@result =[]
|
|
15
|
+
@style =[]
|
|
16
|
+
@nxt_line = 0
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def write_file
|
|
20
|
+
documnt,style = process
|
|
21
|
+
File.write("#{@file_name}", render_to_html(documnt,style))
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
private
|
|
25
|
+
|
|
26
|
+
def process
|
|
27
|
+
while @nxt_line <= @source.length
|
|
28
|
+
parse_line(@source[@nxt_line])
|
|
29
|
+
@nxt_line += 1
|
|
30
|
+
end
|
|
31
|
+
[@result.join(" "),@style.join(",")]
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def parse_line(text)
|
|
35
|
+
case text
|
|
36
|
+
when /^[h|H]\d+\./
|
|
37
|
+
header(text)
|
|
38
|
+
when /^table\./
|
|
39
|
+
table(text)
|
|
40
|
+
when /^[p|P]\./
|
|
41
|
+
paragraph(text)
|
|
42
|
+
when /^\*/
|
|
43
|
+
list(text)
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def header(text)
|
|
48
|
+
tag = text.slice!(/^[h|H]\d+/)
|
|
49
|
+
option = text.gsub!(/^\./, "").slice!(/^\{.*\}/)
|
|
50
|
+
|
|
51
|
+
@result << "<#{tag} id=\"tag_#{@nxt_line}\">#{text.strip}</#{tag}>"
|
|
52
|
+
@style << "\#tag_#{@nxt_line} #{option} \n"
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def paragraph(text)
|
|
56
|
+
tag = text.slice!(/^[p|P]/)
|
|
57
|
+
option = text.gsub!(/^\./, "").slice!(/^\{.*\}/)
|
|
58
|
+
|
|
59
|
+
@result << "<p id=\"tag_#{@nxt_line}\">#{inline_process(text.strip)}</p>"
|
|
60
|
+
@style << "\#tag_#{@nxt_line} #{option} \n"
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
def table(text)
|
|
64
|
+
tag = text.slice!(/^table/)
|
|
65
|
+
option = convert_to_hash(text.gsub!(/^\./, "").slice!(/^\{.*\}/))
|
|
66
|
+
|
|
67
|
+
head = "<tr>"
|
|
68
|
+
text.split(",").each do |i|
|
|
69
|
+
head << "<th>#{i}</th>"
|
|
70
|
+
end
|
|
71
|
+
head << "</tr>"
|
|
72
|
+
|
|
73
|
+
body = []
|
|
74
|
+
option["col"].to_i.times do
|
|
75
|
+
body << "<tr>"
|
|
76
|
+
body << "<td>" + @source[@nxt_line + 1].gsub!(/\,/, "</td><td>") + "</td>"
|
|
77
|
+
body << "</tr>"
|
|
78
|
+
@nxt_line += 1
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
table_content = "<thead>" + head + "</thead>" + "<tbody>" + body.join("") + "</tbody>"
|
|
82
|
+
|
|
83
|
+
@result << "<table id=\"tag_#{@nxt_line}\">#{table_content}</table>"
|
|
84
|
+
@style << "\#tag_#{@nxt_line} #{option} \n"
|
|
85
|
+
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
def list(text)
|
|
89
|
+
tmp = Array(text.gsub!(/^\*\s*/,''))
|
|
90
|
+
while @source[@nxt_line + 1] =~ (/^\*/)
|
|
91
|
+
@nxt_line += 1
|
|
92
|
+
tmp << @source[@nxt_line].gsub!(/^\*\s*/,'')
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
ul = "<ul id=\"tag_#{@nxt_line}\">"
|
|
96
|
+
tmp.each do |i|
|
|
97
|
+
ul << "<li>#{i}</li>"
|
|
98
|
+
end
|
|
99
|
+
ul << "</ul>"
|
|
100
|
+
@result << ul
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
def inline_process(text)
|
|
104
|
+
text.gsub!(/\*\*([^\*]+)\*\*/, '<b>\1</b>')
|
|
105
|
+
text.gsub!(/\_\_([^\_]+)\_\_/, '<i>\1</i>')
|
|
106
|
+
text.gsub!(/\+([^\+]+)\+/, '<ins>\1</ins>')
|
|
107
|
+
text.gsub!(/\^([^\^]+)\^/, '<sup>\1 </sup>')
|
|
108
|
+
text.gsub!(/\?\?([^\?]+)\?\?/, '<sub>\1</sub>')
|
|
109
|
+
text.gsub!(/\~([^\~]+)\~/, '<cite>\1</cite>')
|
|
110
|
+
text.gsub!(/\%([^\%]+)\%/, '<span>\1</span>')
|
|
111
|
+
text.gsub!(/\@([^\@]+)\@/, '<code>\1</code>')
|
|
112
|
+
text.gsub!(/\!\[(.*)\]\((.*)\)/, '<p><img src="\2"/>\1</p>')
|
|
113
|
+
text.gsub!(/\[(.*)\]\((.*)\)/, '<a href="\2">\1</a>')
|
|
114
|
+
text
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
def convert_to_hash(str)
|
|
118
|
+
return unless str.is_a?(String)
|
|
119
|
+
|
|
120
|
+
hash_arg = str.gsub(/[^'"\w\d]/, " ").split.map { |x| x.gsub(/['"]/, "") }
|
|
121
|
+
Hash[*hash_arg]
|
|
122
|
+
end
|
|
123
|
+
|
|
124
|
+
def render_to_html(content = " ",style = " ",language = "en", title = "index")
|
|
125
|
+
return <<-HTML
|
|
126
|
+
<!DOCTYPE html>
|
|
127
|
+
<html lang="#{language}">
|
|
128
|
+
<head>
|
|
129
|
+
<meta charset="utf-8">
|
|
130
|
+
<meta http-equiv="x-ua-compatible" content="ie=edge">
|
|
131
|
+
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
|
|
132
|
+
<title>#{title}</title>
|
|
133
|
+
<style>
|
|
134
|
+
#{style}
|
|
135
|
+
</style>
|
|
136
|
+
</head>
|
|
137
|
+
<body>
|
|
138
|
+
#{content}
|
|
139
|
+
</body>
|
|
140
|
+
</html>
|
|
141
|
+
HTML
|
|
142
|
+
|
|
143
|
+
end
|
|
144
|
+
|
|
145
|
+
end
|
|
146
|
+
end
|
|
147
|
+
|
|
148
|
+
if $PROGRAM_NAME == __FILE__
|
|
149
|
+
ARGV.each do |input|
|
|
150
|
+
Jotdown::Document.new(input).write_file
|
|
151
|
+
end
|
|
152
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: jotdown
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.0.1
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Hamidreza Safari
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: exe
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2024-03-15 00:00:00.000000000 Z
|
|
12
|
+
dependencies: []
|
|
13
|
+
description: jotdown is a short markdown
|
|
14
|
+
email:
|
|
15
|
+
- hamidrezasafari@hotmail.com
|
|
16
|
+
executables: []
|
|
17
|
+
extensions: []
|
|
18
|
+
extra_rdoc_files: []
|
|
19
|
+
files:
|
|
20
|
+
- CHANGELOG.md
|
|
21
|
+
- LICENSE
|
|
22
|
+
- README.md
|
|
23
|
+
- Rakefile
|
|
24
|
+
- jotdown.gemspec
|
|
25
|
+
- lib/.DS_Store
|
|
26
|
+
- lib/hello.html
|
|
27
|
+
- lib/hello.jd
|
|
28
|
+
- lib/jotdown.rb
|
|
29
|
+
- lib/jotdown/version.rb
|
|
30
|
+
homepage: https://github.com/HamidrezaSafari/Jotdown
|
|
31
|
+
licenses: []
|
|
32
|
+
metadata:
|
|
33
|
+
homepage_uri: https://github.com/HamidrezaSafari/Jotdown
|
|
34
|
+
source_code_uri: https://github.com/HamidrezaSafari/Jotdown
|
|
35
|
+
changelog_uri: https://github.com/HamidrezaSafari/Jotdown
|
|
36
|
+
post_install_message:
|
|
37
|
+
rdoc_options: []
|
|
38
|
+
require_paths:
|
|
39
|
+
- lib
|
|
40
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
41
|
+
requirements:
|
|
42
|
+
- - ">="
|
|
43
|
+
- !ruby/object:Gem::Version
|
|
44
|
+
version: 3.0.0
|
|
45
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
46
|
+
requirements:
|
|
47
|
+
- - ">="
|
|
48
|
+
- !ruby/object:Gem::Version
|
|
49
|
+
version: '0'
|
|
50
|
+
requirements: []
|
|
51
|
+
rubygems_version: 3.5.6
|
|
52
|
+
signing_key:
|
|
53
|
+
specification_version: 4
|
|
54
|
+
summary: jotdown is a short markdown
|
|
55
|
+
test_files: []
|