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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 77e4ea7f1cdb7f6e662789c3c9a827d7cf1102794bbec1f487a327f6cafaff8c
4
- data.tar.gz: 4ee0bd4606a2927e6a26face3b4e2decff2321b2ee6f1c7042bc4dea9f97bfc6
3
+ metadata.gz: da4fa3832c34102ae4f89153c51ba51052f7796294a83aa483047f00f404134f
4
+ data.tar.gz: cc046426373c0a37271b3e26d3677ccec42f69916df108dcb033da6d71fb7629
5
5
  SHA512:
6
- metadata.gz: 4fb4491992bab118a0eb70282da7dda3835fce131f8d68b47a945afda47ff71411c0047ad1ce21810be18730082204daf328f07448a0da536cefe7de230fe219
7
- data.tar.gz: a2e1c92b1fdcea5d02203e001564acc528605ca86b6813619522a0d01528af1552e13c7a702f7e677aa45a9559b5c9142fc61a58b51cdbcd59d698c94abd305e
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
@@ -1,5 +1,10 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.3.0 - 2020-12-24
4
+
5
+ - Collapse multiple consecutive code blocks into a single code block
6
+ - Escape HTML entities in code blocks
7
+
3
8
  ## 0.2.0 - 2020-11-30
4
9
 
5
10
  - Fixed requirement of polites files in polites-nanoc
@@ -1,12 +1,12 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- polites (0.2.0)
4
+ polites (0.3.0)
5
5
  nokogiri
6
6
  rubyzip
7
- polites-nanoc (0.2.0)
7
+ polites-nanoc (0.3.0)
8
8
  nanoc (~> 4)
9
- polites (~> 0.2.0)
9
+ polites (~> 0.3.0)
10
10
 
11
11
  GEM
12
12
  remote: https://rubygems.org/
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Polites
4
- VERSION = '0.2.0'
4
+ VERSION = '0.3.0'
5
5
  end
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.2.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-30 00:00:00.000000000 Z
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
@@ -1,6 +0,0 @@
1
- ---
2
- language: ruby
3
- cache: bundler
4
- rvm:
5
- - 2.7.2
6
- before_install: gem install bundler -v 2.1.4