asciidoctor-html5s 0.3.0 → 0.5.1

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: e092a76fce65ac3bf02c38c39060252c0ffc2c1793baa6fa5e349f3c5facd99c
4
- data.tar.gz: 5d28b658e4ed1e4bfccdbc8226d326bd9d33bb15a63a14f84a5b1e37bd56afa2
3
+ metadata.gz: 630da0664ff127034ff14612b42ccfd524f9c37b8dbad7fd86631fef516fc731
4
+ data.tar.gz: 7eef8c8b6512eb08da9cd4bce496e984a6d9b5a21925fc933c13276d40359990
5
5
  SHA512:
6
- metadata.gz: 79fde10526f24f6e819f2475427be3016df9b550da8f4ef035c99961ff8573285a9eed89438629d7a9461c059a601664c228f64caa46bec781728de7b421f6e1
7
- data.tar.gz: 5beea3877ff5ad48750b5be4ca61b5bebce4daa9b64054e2b5220d3234d1094d3b4e33c71737a8cf07d9ccf1ff2c3d886bf026bfddbefb94595d990b57b75e86
6
+ metadata.gz: b8919b949ca260a57dc2555f8ee3bff088b4608cef4ac107be9fa922def409054ffb2ef0b6ea4ece811daf19e4528be910cc5d8ae11a2136de320b688be6cfa4
7
+ data.tar.gz: 717270402b7f40ba2266e0d13594b6bdec16a644e76f6c32454812f9f10fae0806e483bfa7d97b303f2213acb0740db33404903d561b7e3c27be89c516a474ae
data/README.adoc CHANGED
@@ -5,7 +5,7 @@
5
5
  :gh-branch: master
6
6
 
7
7
  ifdef::env-github[]
8
- image:https://travis-ci.org/{gh-name}.svg?branch={gh-branch}[Build Status, link="https://travis-ci.org/{gh-name}"]
8
+ image:https://github.com/{gh-name}/workflows/CI/badge.svg[CI Status, link=https://github.com/{gh-name}/actions?query=workflow%3A%22CI%22]
9
9
  image:https://img.shields.io/gem/v/{gem-name}.svg?style=flat[Gem Version, link="https://rubygems.org/gems/{gem-name}"]
10
10
  image:https://img.shields.io/npm/v/{gem-name}.svg?style=flat[npm Version, link="https://www.npmjs.org/package/{gem-name}"]
11
11
  endif::env-github[]
@@ -125,6 +125,19 @@ link=none / link=false::
125
125
  Both block image and inline image supports additional attribute `loading` (see https://developer.mozilla.org/en-US/docs/Web/Performance/Lazy_loading#Images[Lazy loading] on MDN for more information).
126
126
 
127
127
 
128
+ === Additional Inline Formatting Roles
129
+
130
+ del::
131
+ `++[del]#deleted text#++` is rendered as `<del>deleted text</del>`.
132
+
133
+ ins::
134
+ `++[ins]#inserted text#++` is rendered as `<ins>inserted text</ins>`.
135
+
136
+ strike::
137
+ `++[strike]#inserted text#++` is rendered as `<s>inserted text</s>`.
138
+ This is an alias for `line-through`.
139
+
140
+
128
141
  == Requirements
129
142
 
130
143
  Note: This converter consists of https://github.com/slim-template/slim/[Slim] templates, but they are precompiled into pure Ruby code using https://github.com/jirutka/asciidoctor-templates-compiler/[asciidoctor-templates-compiler], so you don’t need Slim to use it!
@@ -133,7 +146,7 @@ ifndef::npm-readme[]
133
146
  === Ruby
134
147
 
135
148
  * https://www.ruby-lang.org/[Ruby] 2.0+ or http://jruby.org/[JRuby] 9.1+
136
- * https://rubygems.org/gems/asciidoctor/[Asciidoctor] 1.5.5+
149
+ * https://rubygems.org/gems/asciidoctor/[Asciidoctor] 1.5.7+
137
150
  * https://rubygems.org/gems/thread_safe/[thread_safe] (not required, but recommended for Ruby MRI)
138
151
 
139
152
 
@@ -141,7 +154,7 @@ ifndef::npm-readme[]
141
154
  endif::npm-readme[]
142
155
 
143
156
  * https://nodejs.org/[Node.js]
144
- * https://www.npmjs.com/package/@asciidoctor/core[@asciidoctor/core] >=2.0.0 <2.2.0
157
+ * https://www.npmjs.com/package/@asciidoctor/core[@asciidoctor/core] >=2.0.0 <3.0.0
145
158
 
146
159
 
147
160
  == Installation
@@ -21,15 +21,14 @@ EOF
21
21
 
22
22
  s.required_ruby_version = '>= 2.0'
23
23
 
24
- s.add_runtime_dependency 'asciidoctor', '>= 1.5.5', '< 3.0'
24
+ s.add_runtime_dependency 'asciidoctor', '>= 1.5.7', '< 3.0'
25
25
  s.add_runtime_dependency 'thread_safe', '~> 0.3.4'
26
26
 
27
- s.add_development_dependency 'asciidoctor-doctest', '= 2.0.0.beta.6'
27
+ s.add_development_dependency 'asciidoctor-doctest', '= 2.0.0.beta.7'
28
28
  s.add_development_dependency 'asciidoctor-templates-compiler', '~> 0.6.0'
29
29
  s.add_development_dependency 'bundler', '>= 1.6'
30
- s.add_development_dependency 'coderay', '~> 1.1'
31
30
  s.add_development_dependency 'pandoc-ruby', '~> 2.0'
32
- s.add_development_dependency 'rake', '~> 12.0'
31
+ s.add_development_dependency 'rake', '~> 13.0'
33
32
  s.add_development_dependency 'slim', '~> 3.0'
34
33
  s.add_development_dependency 'slim-htag', '~> 0.1.0'
35
34
  end
@@ -1,4 +1,4 @@
1
- - if has_header?
1
+ - if header?
2
2
  - unless notitle
3
3
  h1 =header.title
4
4
  - if [:author, :revnumber, :revdate, :revremark].any? {|a| attr? a }
@@ -1,13 +1,7 @@
1
- - case style
2
- - when 'qanda'
3
- include _qanda.html
4
- - when 'horizontal'
5
- include _hdlist.html
6
- - else
7
- = block_with_title :class=>['dlist', style]
8
- dl
9
- - items.each do |terms, dd|
10
- - [*terms].each do |dt|
11
- dt =dt.text
12
- - unless dd.nil?
13
- dd =(print_item_content dd)
1
+ = block_with_title :class=>['dlist', style], :role=>('doc-qna' if style == 'qanda')
2
+ dl class=style
3
+ - items.each do |terms, dd|
4
+ - [*terms].each do |dt|
5
+ dt =dt.text
6
+ - unless dd.nil?
7
+ dd =(print_item_content dd)
@@ -1,9 +1,13 @@
1
1
  doctype 5
2
2
  html lang=(attr :lang, 'en' unless attr? :nolang)
3
+ / Render the document content before styles_and_scripts -
4
+ / SyntaxHighlighter#docinfo must be called after SyntaxHighlighter#highlight
5
+ / because some highlighter plugins emit style/script tags only when
6
+ / #highlight was called at least once.
7
+ - document_content = content
3
8
  head
4
9
  meta charset=(attr :encoding, 'UTF-8')
5
- /[if IE]
6
- meta http-equiv="X-UA-Compatible" content="IE=edge"
10
+ meta http-equiv="X-UA-Compatible" content="IE=edge"
7
11
  meta name='viewport' content='width=device-width, initial-scale=1.0'
8
12
  meta name='generator' content="Asciidoctor #{attr 'asciidoctor-version'}"
9
13
  = html_meta_if 'application-name', (attr 'app-name')
@@ -17,12 +21,16 @@ html lang=(attr :lang, 'en' unless attr? :nolang)
17
21
  =docinfo_content
18
22
  body [
19
23
  id=id
20
- class=[(attr :doctype), ("#{attr 'toc-class'} toc-#{attr 'toc-position', 'left'}" if (attr? 'toc-class') && (attr? :toc) && (attr? 'toc-placement', 'auto'))]
24
+ class=[(attr :doctype),
25
+ ("#{attr 'toc-class'} toc-#{attr 'toc-position', 'left'}" if (attr? 'toc-class') && (attr? :toc) && (attr? 'toc-placement', 'auto')),
26
+ (attr :docrole) || (attr :role)]
21
27
  style=style_value(max_width: (attr 'max-width')) ]
28
+ - unless (docinfo_content = (docinfo :header)).empty?
29
+ =docinfo_content
22
30
  - unless noheader
23
31
  header
24
32
  include _header.html
25
- #content =content
33
+ #content =document_content
26
34
  - unless !footnotes? || (attr? :nofootnotes)
27
35
  include _footnotes.html
28
36
  - unless nofooter
@@ -1,4 +1,4 @@
1
- - if !notitle && has_header?
1
+ - if !notitle && header?
2
2
  h1 id=id =header.title
3
3
  - if node.sections? && (attr? :toc) && (attr 'toc-placement', 'auto') == 'auto'
4
4
  include _toc.html
@@ -1,3 +1,11 @@
1
- = block_with_caption :top, :class=>'example-block'
2
- .example
3
- =content
1
+ - if option? :collapsible
2
+ details id=id class=role open=(option? :open)
3
+ - if title
4
+ summary
5
+ =title
6
+ .content
7
+ =content
8
+ - else
9
+ = block_with_caption :top, :class=>'example-block'
10
+ .example
11
+ =content
@@ -1,5 +1,4 @@
1
1
  require 'asciidoctor/html5s'
2
- require 'asciidoctor/html5s/logger'
3
2
  require 'date' unless RUBY_PLATFORM == 'opal'
4
3
 
5
4
  # Add custom functions to this module that you want to use in your Slim
@@ -8,10 +7,11 @@ require 'date' unless RUBY_PLATFORM == 'opal'
8
7
  module Slim::Helpers
9
8
 
10
9
  # URIs of external assets.
11
- FONT_AWESOME_URI = '//cdn.jsdelivr.net/npm/font-awesome@4.7.0/css/font-awesome.min.css'
12
- HIGHLIGHTJS_BASE_URI = '//cdn.jsdelivr.net/gh/highlightjs/cdn-release@9.12.0/build/'
13
- KATEX_CSS_URI = '//cdn.jsdelivr.net/npm/katex@0.9.0/dist/katex.min.css'
14
- KATEX_JS_URI = '//cdn.jsdelivr.net/npm/katex@0.9.0/dist/katex.min.js'
10
+ CDN_BASE_URI = 'https://cdnjs.cloudflare.com/ajax/libs' # for highlighters in Asciidoctor >=2.0.0
11
+ FONT_AWESOME_URI = 'https://cdn.jsdelivr.net/npm/font-awesome@4.7.0/css/font-awesome.min.css'
12
+ HIGHLIGHTJS_BASE_URI = 'https://cdn.jsdelivr.net/gh/highlightjs/cdn-release@9.15.1/build/'
13
+ KATEX_CSS_URI = 'https://cdn.jsdelivr.net/npm/katex@0.11.1/dist/katex.min.css'
14
+ KATEX_JS_URI = 'https://cdn.jsdelivr.net/npm/katex@0.11.1/dist/katex.min.js'
15
15
 
16
16
  # Defaults
17
17
  DEFAULT_HIGHLIGHTJS_THEME = 'github'
@@ -53,7 +53,7 @@ module Slim::Helpers
53
53
 
54
54
  # @return [Logger]
55
55
  def log
56
- @_html5s_logger ||= ::Asciidoctor::Html5s::Logging.default_logger
56
+ ::Asciidoctor::LoggerManager.logger
57
57
  end
58
58
 
59
59
  ##
@@ -376,15 +376,29 @@ module Slim::Helpers
376
376
  # Returns the captioned section's title, optionally numbered.
377
377
  #
378
378
  # @param sec [Asciidoctor::Section] the section node (default: self).
379
+ # @param drop_anchors [Boolean] Remove +<a>+ tags from the title?
379
380
  # @return [String]
380
381
  #
381
- def section_title(sec = self)
382
- sectnumlevels = document.attr(:sectnumlevels, DEFAULT_SECTNUMLEVELS).to_i
382
+ def section_title(sec = self, drop_anchors: false)
383
+ title =
384
+ if sec.caption
385
+ sec.captioned_title
386
+ elsif sec.numbered && sec.level <= document.attr(:sectnumlevels, DEFAULT_SECTNUMLEVELS).to_i
387
+ if sec.level < 2 && document.doctype == 'book' && %w[chapter part].include?(sec.sectname)
388
+ signifier = document.attr("#{sec.sectname}-signifier")
389
+ sectnum = sec.sectname == 'part' ? sec.sectnum(nil, ':') : sec.sectnum
390
+ "#{signifier&.+ ' '}#{sectnum} #{sec.title}"
391
+ else
392
+ "#{sec.sectnum} #{sec.title}"
393
+ end
394
+ else
395
+ sec.title
396
+ end
383
397
 
384
- if sec.numbered && !sec.caption && sec.level <= sectnumlevels
385
- [sec.sectnum, sec.captioned_title].join(' ')
398
+ if drop_anchors && title.include?('<a')
399
+ title.gsub(/<(?:a[^>+]+|\/a)>/, '')
386
400
  else
387
- sec.captioned_title
401
+ title
388
402
  end
389
403
  end
390
404
 
@@ -396,7 +410,12 @@ module Slim::Helpers
396
410
  end
397
411
 
398
412
  def link_rel
399
- 'noopener' if option?('noopener') || attr(:window) == '_blank'
413
+ rel = [
414
+ ('nofollow' if option?('nofollow')),
415
+ ('noopener' if option?('noopener') || local_attr(:window) == '_blank')
416
+ ].compact
417
+
418
+ rel.empty? ? nil : rel.join(' ')
400
419
  end
401
420
 
402
421
  #--------------------------------------------------------
@@ -455,15 +474,19 @@ module Slim::Helpers
455
474
  #
456
475
 
457
476
  ##
458
- # @return [String] a canonical name of the source-highlighter to be used as
459
- # a style class.
460
- def highlighter
461
- @_html5s_highlighter ||=
462
- case (highlighter = document.attr('source-highlighter'))
463
- when 'coderay'; 'CodeRay'
464
- when 'highlight.js'; 'highlightjs'
465
- else highlighter
466
- end
477
+ # See {Asciidoctor::SyntaxHighlighter#format}.
478
+ #
479
+ # @return [String, nil] a rendered HTML.
480
+ def formatted_source
481
+ hl = document.syntax_highlighter or return nil
482
+
483
+ opts = { nowrap: nowrap? }
484
+ if hl.highlight?
485
+ opts[:css_mode] = document.attr("#{hl.name}-css", :class).to_sym
486
+ opts[:style] = document.attr("#{hl.name}-style")
487
+ end
488
+
489
+ hl.format(self, source_lang, opts)
467
490
  end
468
491
 
469
492
  ##
@@ -481,6 +504,15 @@ module Slim::Helpers
481
504
  local_attr :language, false
482
505
  end
483
506
 
507
+ # This is needed only for Asciidoctor <2.0.0.
508
+ def source_code_class
509
+ if document.attr? 'source-highlighter', 'highlightjs'
510
+ "language-#{source_lang || 'none'} hljs"
511
+ elsif source_lang
512
+ "language-#{source_lang}"
513
+ end
514
+ end
515
+
484
516
  #--------------------------------------------------------
485
517
  # block_open
486
518
  #
@@ -502,7 +534,7 @@ without a title when doctype is book. Excluding block content.'
502
534
  def partintro_allowed?
503
535
  if result = (level != 0 || parent.context != :section || document.doctype != 'book')
504
536
  log.warn "asciidoctor: ERROR: partintro block can only be used when doctype
505
- is book and it's a child of a book part. Excluding block content."
537
+ is book and must be a child of a book part. Excluding block content."
506
538
  end
507
539
  !result
508
540
  end
@@ -511,13 +543,13 @@ is book and it's a child of a book part. Excluding block content."
511
543
  # block_table
512
544
  #
513
545
 
514
- def autowidth?
515
- option? :autowidth
546
+ def autowidth?(node = self)
547
+ node.option? :autowidth
516
548
  end
517
549
 
518
- def spread?
550
+ def stretch?
519
551
  if !autowidth? || local_attr?('width')
520
- 'spread' if attr? :tablepcwidth, 100
552
+ 'stretch' if attr? :tablepcwidth, 100
521
553
  end
522
554
  end
523
555
 
@@ -535,7 +567,8 @@ is book and it's a child of a book part. Excluding block content."
535
567
  when :vimeo
536
568
  params = {
537
569
  autoplay: (1 if option? 'autoplay'),
538
- loop: (1 if option? 'loop')
570
+ loop: (1 if option? 'loop'),
571
+ muted: (1 if option? 'muted')
539
572
  }
540
573
  start_anchor = "#at=#{attr :start}" if attr? :start
541
574
  "//player.vimeo.com/video/#{attr :target}#{start_anchor}#{url_query params}"
@@ -549,6 +582,7 @@ is book and it's a child of a book part. Excluding block content."
549
582
  list: (attr :list, list_id),
550
583
  autoplay: (1 if option? 'autoplay'),
551
584
  loop: (1 if option? 'loop'),
585
+ muted: (1 if option? 'muted'),
552
586
  controls: (0 if option? 'nocontrols')
553
587
  }
554
588
  "//www.youtube.com/embed/#{video_id}#{url_query params}"
@@ -603,10 +637,9 @@ is book and it's a child of a book part. Excluding block content."
603
637
  stylesheet = attr :stylesheet
604
638
  stylesdir = attr :stylesdir, ''
605
639
  default_style = ::Asciidoctor::DEFAULT_STYLESHEET_KEYS.include? stylesheet
606
- linkcss = attr?(:linkcss) || safe >= ::Asciidoctor::SafeMode::SECURE
607
640
  ss = ::Asciidoctor::Stylesheets.instance
608
641
 
609
- if linkcss
642
+ if attr?(:linkcss)
610
643
  path = default_style ? ::Asciidoctor::DEFAULT_STYLESHEET_NAME : stylesheet
611
644
  styles << { href: [stylesdir, path] }
612
645
  elsif default_style
@@ -629,23 +662,15 @@ is book and it's a child of a book part. Excluding block content."
629
662
  scripts << { text: KATEX_RENDER_CODE }
630
663
  end
631
664
 
632
- case attr 'source-highlighter'
633
- when 'coderay'
634
- if attr('coderay-css', 'class') == 'class'
635
- if linkcss
636
- styles << { href: [stylesdir, ss.coderay_stylesheet_name] }
637
- else
638
- styles << { text: ss.coderay_stylesheet_data }
639
- end
640
- end
665
+ if !defined?(::Asciidoctor::SyntaxHighlighter) # Asciidoctor <2.0.0
666
+ if attr? 'source-highlighter', 'highlightjs'
667
+ hjs_base = attr :highlightjsdir, HIGHLIGHTJS_BASE_URI
668
+ hjs_theme = attr 'highlightjs-theme', DEFAULT_HIGHLIGHTJS_THEME
641
669
 
642
- when 'highlightjs'
643
- hjs_base = attr :highlightjsdir, HIGHLIGHTJS_BASE_URI
644
- hjs_theme = attr 'highlightjs-theme', DEFAULT_HIGHLIGHTJS_THEME
645
-
646
- scripts << { src: [hjs_base, 'highlight.min.js'] }
647
- scripts << { text: 'hljs.initHighlightingOnLoad()' }
648
- styles << { href: [hjs_base, "styles/#{hjs_theme}.min.css"] }
670
+ scripts << { src: [hjs_base, 'highlight.min.js'] }
671
+ scripts << { text: 'hljs.initHighlightingOnLoad()' }
672
+ styles << { href: [hjs_base, "styles/#{hjs_theme}.min.css"] }
673
+ end
649
674
  end
650
675
 
651
676
  styles.each do |item|
@@ -664,6 +689,15 @@ is book and it's a child of a book part. Excluding block content."
664
689
  end
665
690
  end
666
691
 
692
+ if defined?(::Asciidoctor::SyntaxHighlighter) && (hl = syntax_highlighter) # Asciidoctor >=2.0.0
693
+ # XXX: We don't care about the declared location and put all to head.
694
+ [:head, :footer].each do |location|
695
+ if hl.docinfo?(location)
696
+ tags << hl.docinfo(location, self, cdn_base_url: CDN_BASE_URI, linkcss: attr?(:linkcss))
697
+ end
698
+ end
699
+ end
700
+
667
701
  tags.join("\n")
668
702
  end
669
703
 
@@ -678,27 +712,21 @@ is book and it's a child of a book part. Excluding block content."
678
712
  text
679
713
  elsif (path = local_attr :path)
680
714
  path
681
- elsif document.respond_to? :catalog # Asciidoctor >=1.5.6
715
+ else
682
716
  ref = document.catalog[:refs][attr :refid]
683
717
  if ref.kind_of? Asciidoctor::AbstractNode
684
- ref.xreftext((@_html5s_xrefstyle ||= document.attributes['xrefstyle']))
718
+ ref.xreftext(attr(:xrefstyle, nil, true))
685
719
  end
686
- else # Asciidoctor < 1.5.6
687
- document.references[:ids][attr :refid || target]
688
720
  end
689
721
  (str || "[#{attr :refid}]").tr_s("\n", ' ')
690
722
  end
691
723
 
692
724
  # @return [String, nil] text of the bibref anchor, or +nil+ if not found.
693
725
  def bibref_text
694
- if document.respond_to? :catalog # Asciidoctor >=1.5.6
695
- if ::Asciidoctor::VERSION[0] == '1'
696
- text
697
- else # Asciidoctor >= 2.0.0
698
- "[#{reftext || id}]"
699
- end
700
- else
701
- "[#{target}]"
726
+ if ::Asciidoctor::VERSION[0] == '1'
727
+ text
728
+ else # Asciidoctor >= 2.0.0
729
+ "[#{reftext || id}]"
702
730
  end
703
731
  end
704
732
 
@@ -1,12 +1,10 @@
1
1
  - case type
2
2
  - when :xref
3
- a href=target =xref_text
3
+ a href=target class=role =xref_text
4
4
  - when :ref
5
- / "target" is for backward compat. with Asciidoctor <1.5.6
6
- a id=(id || target) aria-hidden='true'
5
+ a id=id aria-hidden='true'
7
6
  - when :bibref
8
- / "target" is for backward compat. with Asciidoctor <1.5.6
9
- a id=(id || target) aria-hidden='true'
7
+ a id=id aria-hidden='true'
10
8
  =bibref_text
11
9
  - else
12
10
  a id=id class=role href=target target=(attr :window) rel=link_rel title=(attr :title) =text
@@ -1 +1,2 @@
1
- b.button =text
1
+ kbd.button
2
+ samp =text
@@ -1,7 +1,7 @@
1
1
  - if (keys = attr 'keys').size == 1
2
- kbd =keys.first
2
+ kbd.key =keys.first
3
3
  - else
4
4
  kbd.keyseq
5
5
  - keys.each_with_index do |key, idx|
6
6
  ="+" unless idx.zero?
7
- kbd =key
7
+ kbd.key =key