polites 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/ci.yml +17 -0
- data/.yardopts +1 -1
- data/CHANGELOG.md +5 -0
- data/Gemfile.lock +3 -3
- data/README.md +2 -0
- data/lib/polites/code_grouper.rb +28 -0
- data/lib/polites/html_formatter.rb +6 -2
- data/lib/polites/version.rb +1 -1
- metadata +4 -3
- data/.travis.yml +0 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: da4fa3832c34102ae4f89153c51ba51052f7796294a83aa483047f00f404134f
|
4
|
+
data.tar.gz: cc046426373c0a37271b3e26d3677ccec42f69916df108dcb033da6d71fb7629
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d07b0f5a9c11401c5bddab7bd82d253d8b75fae5fd40922a25a62f46a3421170a1a6421613ca32253f1e72d1b1b9d51c26e3d3607dcd4cef66872412b1f63a18
|
7
|
+
data.tar.gz: ac8ffa27cafcf07bb45eea77f51282c41b587bceb9eaf8021c91a9bca4958ee79ac2e0c6706268256e6b5f3a36c54d060bc9aee6cd27815f06b52af86ad94b0e
|
@@ -0,0 +1,17 @@
|
|
1
|
+
---
|
2
|
+
name: CI
|
3
|
+
on:
|
4
|
+
push:
|
5
|
+
branches: [main]
|
6
|
+
pull_request:
|
7
|
+
branches: [main]
|
8
|
+
jobs:
|
9
|
+
test:
|
10
|
+
runs-on: ubuntu-latest
|
11
|
+
steps:
|
12
|
+
- uses: actions/checkout@v2
|
13
|
+
- uses: ruby/setup-ruby@v1
|
14
|
+
with:
|
15
|
+
bundler-cache: true
|
16
|
+
- name: Run tests
|
17
|
+
run: bundle exec rake
|
data/.yardopts
CHANGED
@@ -1 +1 @@
|
|
1
|
-
--no-private lib/**/*.rb --readme README.md --markup markdown --markup-provider kramdown - LICENSE.txt CODE_OF_CONDUCT.md
|
1
|
+
--no-private lib/**/*.rb --readme README.md --markup markdown --markup-provider kramdown - LICENSE.txt CODE_OF_CONDUCT.md CHANGELOG.md
|
data/CHANGELOG.md
CHANGED
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -4,6 +4,8 @@ Polites allows you to work with files generated by the [Ulysses](https://ulysses
|
|
4
4
|
|
5
5
|
Most importantly, this gem allows you to take Ulysses .ulyz files as input and transform them into HTML, all from Ruby. Additionally, you can extract embedded media files from the .ulyz file.
|
6
6
|
|
7
|
+
See the [API docs](https://rubydoc.info/gems/polites).
|
8
|
+
|
7
9
|
## Installation
|
8
10
|
|
9
11
|
Add this line to your application's Gemfile:
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Polites
|
4
|
+
# Take a list of items and collapse a collection of subsequent code blocks
|
5
|
+
# into a single one separated by newlines.
|
6
|
+
class CodeGrouper
|
7
|
+
# @param [Array<Polites::Node>] items
|
8
|
+
# @return [Array<Polites::Node>]
|
9
|
+
def call(items)
|
10
|
+
items
|
11
|
+
.chunk { |i| i.is_a?(Block::CodeBlock) }.to_a
|
12
|
+
.inject([]) do |acc, (k, contents)|
|
13
|
+
acc + (k ? [combine(contents)] : contents)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def combine(items)
|
20
|
+
Block::CodeBlock.new(
|
21
|
+
items
|
22
|
+
.inject([]) { |acc, item| acc + item.children + [Text.new("\n")] }
|
23
|
+
.slice(0..-2),
|
24
|
+
items.first.syntax
|
25
|
+
)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -1,10 +1,13 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'cgi'
|
4
|
+
|
3
5
|
require_relative './block'
|
4
6
|
require_relative './span'
|
5
7
|
require_relative './text'
|
6
8
|
require_relative './sheet'
|
7
9
|
require_relative './list_indenter'
|
10
|
+
require_relative './code_grouper'
|
8
11
|
|
9
12
|
module Polites
|
10
13
|
# Takes an AST as produced by {Parser} and generates HTML output from it.
|
@@ -16,6 +19,7 @@ module Polites
|
|
16
19
|
def initialize
|
17
20
|
@footnotes = []
|
18
21
|
@indenter = ListIndenter.new
|
22
|
+
@code_grouper = CodeGrouper.new
|
19
23
|
end
|
20
24
|
|
21
25
|
# Apply formatting to the given AST.
|
@@ -38,7 +42,7 @@ module Polites
|
|
38
42
|
end
|
39
43
|
nl + tag(tag_name, NL + call(obj.children, join: NL) + NL) + nl
|
40
44
|
when Array
|
41
|
-
coll = indent ? @indenter.call(obj) : obj
|
45
|
+
coll = indent ? @code_grouper.call(@indenter.call(obj)) : obj
|
42
46
|
coll.map { |c| call(c) }.join(join)
|
43
47
|
when Block::UnorderedList, Block::OrderedList
|
44
48
|
tag(:li, call(obj.children))
|
@@ -59,7 +63,7 @@ module Polites
|
|
59
63
|
when Block::Blockquote
|
60
64
|
tag(:blockquote, tag(:p, call(obj.children)))
|
61
65
|
when Block::CodeBlock
|
62
|
-
tag(:pre, tag(:code, call(obj.children), class: "language-#{obj.syntax}"))
|
66
|
+
tag(:pre, tag(:code, CGI.escape_html(call(obj.children)), class: "language-#{obj.syntax}"))
|
63
67
|
when Block::Divider
|
64
68
|
tag(:hr)
|
65
69
|
when Span::Strong
|
data/lib/polites/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: polites
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Arjan van der Gaag
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-12-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: nokogiri
|
@@ -47,11 +47,11 @@ executables:
|
|
47
47
|
extensions: []
|
48
48
|
extra_rdoc_files: []
|
49
49
|
files:
|
50
|
+
- ".github/workflows/ci.yml"
|
50
51
|
- ".gitignore"
|
51
52
|
- ".rspec"
|
52
53
|
- ".rubocop.yml"
|
53
54
|
- ".tool-versions"
|
54
|
-
- ".travis.yml"
|
55
55
|
- ".yardopts"
|
56
56
|
- CHANGELOG.md
|
57
57
|
- CODE_OF_CONDUCT.md
|
@@ -80,6 +80,7 @@ files:
|
|
80
80
|
- lib/polites/block/paragraph.rb
|
81
81
|
- lib/polites/block/unordered_list.rb
|
82
82
|
- lib/polites/cli.rb
|
83
|
+
- lib/polites/code_grouper.rb
|
83
84
|
- lib/polites/convert.rb
|
84
85
|
- lib/polites/doc/_index.html
|
85
86
|
- lib/polites/doc/class_list.html
|