qiita-markdown 0.16.1 → 0.16.2

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of qiita-markdown might be problematic. Click here for more details.

checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 01b805ffe8201bb8805e335ef00b5a2b08164115
4
- data.tar.gz: 15a749e779263c51422f416cd4f03927131628dd
3
+ metadata.gz: 6930365463090ad83b3ca6a7ac378079c64366fa
4
+ data.tar.gz: cf044ca468133457b097cf751a1f39b524a64a45
5
5
  SHA512:
6
- metadata.gz: 53275947310ee3fc879b5ed2934ec68f30d9f2a7b3a0cac3cf83358337bf490902168454d4d70979aacce9993ce16ebb9ed835dc5cbf22420a84d726afde9c11
7
- data.tar.gz: eaf5964c573eb43bd0b9ec008a67df6d5a9c29edb0b8a959f2c54372a6f8243f6e097785de040c43ba1a4cef18e7ccccf037239b2766e5054f70eb38d85ddf27
6
+ metadata.gz: 2dee229d39ace728a8d7cba1bc274eb3d4cd89b7b928e2e34f2e7182fd856e2c6bbbed62243e904719546b1df15183bf72f06616fa07254d67f068adf7e4a147
7
+ data.tar.gz: 9f153ddf0817a66ecc7aa9d09215705d573e8da56845f133e87cf37257e36ac6b8135db4ddcbbfbdfde1e7c6a7e58c8453e65f9476fdf3311ae3a8f7e4b275be
data/CHANGELOG.md CHANGED
@@ -1,3 +1,8 @@
1
+ ## 0.16.2
2
+
3
+ - Add timeout support to `SyntaxHighlightFilter`
4
+ - Make `SyntaxHighlightFilter` process code blocks faster when their specified language is unknown to Pygments
5
+
1
6
  ## 0.16.1
2
7
 
3
8
  - Fix a group mention bug that unexpectedly removes preceding space
data/README.md CHANGED
@@ -1,17 +1,24 @@
1
- # Qiita::Markdown [![Build Status](https://travis-ci.org/increments/qiita-markdown.svg)](https://travis-ci.org/increments/qiita-markdown) [![Code Climate](https://codeclimate.com/github/increments/qiita-markdown/badges/gpa.svg)](https://codeclimate.com/github/increments/qiita-markdown) [![Test Coverage](https://codeclimate.com/github/increments/qiita-markdown/badges/coverage.svg)](https://codeclimate.com/github/increments/qiita-markdown)
1
+ # Qiita::Markdown
2
+
3
+ [[![Gem](https://img.shields.io/gem/v/qiita-markdown.svg)]()](https://rubygems.org/gems/qiita-markdown)
4
+ [![Build Status](https://travis-ci.org/increments/qiita-markdown.svg)](https://travis-ci.org/increments/qiita-markdown)
5
+ [![Code Climate](https://codeclimate.com/github/increments/qiita-markdown/badges/gpa.svg)](https://codeclimate.com/github/increments/qiita-markdown)
6
+ [![Test Coverage](https://codeclimate.com/github/increments/qiita-markdown/badges/coverage.svg)](https://codeclimate.com/github/increments/qiita-markdown)
7
+
2
8
  Qiita-specified markdown processor.
3
9
 
4
- * Markdown conversion
5
- * Sanitization
6
- * Code and language detection
7
- * Task list
8
- * ToC
9
- * Emoji
10
- * Syntax highlighting
11
- * Mention
12
- * Footnotes
10
+ - Markdown conversion
11
+ - Sanitization
12
+ - Code and language detection
13
+ - Task list
14
+ - ToC
15
+ - Emoji
16
+ - Syntax highlighting
17
+ - Mention
18
+ - Footnotes
13
19
 
14
20
  ## Basic Usage
21
+
15
22
  Qiita::Markdown::Processor provides markdown rendering logic.
16
23
 
17
24
  ```ruby
@@ -34,6 +41,7 @@ processor.call(markdown)
34
41
  ```
35
42
 
36
43
  ### Filters
44
+
37
45
  Qiita::Markdown is built on [jch/html-pipeline](https://github.com/jch/html-pipeline).
38
46
  Add your favorite html-pipeline-compatible filters.
39
47
 
@@ -44,6 +52,7 @@ processor.call(text)
44
52
  ```
45
53
 
46
54
  ### Context
55
+
47
56
  `.new` and `#call` can take optional context as a Hash with following keys:
48
57
 
49
58
  ```
@@ -69,6 +78,7 @@ processor.call(text)
69
78
  ```
70
79
 
71
80
  ## Rendering Summary
81
+
72
82
  There's another processor Qiita::Markdown::SummaryProcessor,
73
83
  which is for rendering a summary of markdown document.
74
84
  It simplifies a document by removing complex markups
@@ -3,13 +3,23 @@ module Qiita
3
3
  module Filters
4
4
  class SyntaxHighlight < HTML::Pipeline::Filter
5
5
  DEFAULT_LANGUAGE = "text"
6
+ DEFAULT_TIMEOUT = Float::INFINITY
6
7
 
7
8
  def call
9
+ elapsed = 0
10
+ timeout_fallback_language = nil
8
11
  doc.search("pre").each do |node|
9
- Highlighter.call(
10
- default_language: default_language,
11
- node: node,
12
- )
12
+ elapsed += measure_time do
13
+ Highlighter.call(
14
+ default_language: default_language,
15
+ node: node,
16
+ specific_language: timeout_fallback_language,
17
+ )
18
+ end
19
+ if elapsed >= timeout
20
+ timeout_fallback_language = DEFAULT_LANGUAGE
21
+ result[:syntax_highlight_timed_out] = true
22
+ end
13
23
  end
14
24
  doc
15
25
  end
@@ -20,14 +30,26 @@ module Qiita
20
30
  context[:default_language] || DEFAULT_LANGUAGE
21
31
  end
22
32
 
33
+ def measure_time
34
+ t1 = Time.now
35
+ yield
36
+ t2 = Time.now
37
+ t2 - t1
38
+ end
39
+
40
+ def timeout
41
+ context[:syntax_highlight_timeout] || DEFAULT_TIMEOUT
42
+ end
43
+
23
44
  class Highlighter
24
45
  def self.call(*args)
25
46
  new(*args).call
26
47
  end
27
48
 
28
- def initialize(default_language: nil, node: nil)
49
+ def initialize(default_language: nil, node: nil, specific_language: nil)
29
50
  @default_language = default_language
30
51
  @node = node
52
+ @specific_language = specific_language
31
53
  end
32
54
 
33
55
  def call
@@ -61,7 +83,7 @@ module Qiita
61
83
  end
62
84
 
63
85
  def highlighted_node
64
- if specific_language
86
+ if specific_language && Pygments::Lexer.find(specific_language)
65
87
  begin
66
88
  highlight(specific_language).presence or raise
67
89
  rescue
@@ -89,7 +111,7 @@ module Qiita
89
111
  end
90
112
 
91
113
  def specific_language
92
- @node["lang"]
114
+ @specific_language || @node["lang"]
93
115
  end
94
116
  end
95
117
  end
@@ -1,5 +1,5 @@
1
1
  module Qiita
2
2
  module Markdown
3
- VERSION = "0.16.1"
3
+ VERSION = "0.16.2"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: qiita-markdown
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.16.1
4
+ version: 0.16.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryo Nakamura
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-11-24 00:00:00.000000000 Z
11
+ date: 2016-12-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: gemoji
@@ -307,7 +307,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
307
307
  version: '0'
308
308
  requirements: []
309
309
  rubyforge_project:
310
- rubygems_version: 2.4.5.1
310
+ rubygems_version: 2.5.2
311
311
  signing_key:
312
312
  specification_version: 4
313
313
  summary: Qiita-specified markdown processor.