asciidoctor-html5s 0.3.0 → 0.4.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e092a76fce65ac3bf02c38c39060252c0ffc2c1793baa6fa5e349f3c5facd99c
4
- data.tar.gz: 5d28b658e4ed1e4bfccdbc8226d326bd9d33bb15a63a14f84a5b1e37bd56afa2
3
+ metadata.gz: 9e9dfca08be8f1cae2bc0477f473df93fb71c88a84396467342926852f1cc3c9
4
+ data.tar.gz: 80da368fe359dc4107302113a43b2e0ccbf62b782390de9a9883bbcc9f9e8a4c
5
5
  SHA512:
6
- metadata.gz: 79fde10526f24f6e819f2475427be3016df9b550da8f4ef035c99961ff8573285a9eed89438629d7a9461c059a601664c228f64caa46bec781728de7b421f6e1
7
- data.tar.gz: 5beea3877ff5ad48750b5be4ca61b5bebce4daa9b64054e2b5220d3234d1094d3b4e33c71737a8cf07d9ccf1ff2c3d886bf026bfddbefb94595d990b57b75e86
6
+ metadata.gz: fc1548921c0f4d7c9e8b53fe076505814f748336787cd339c0b93c2d66c7f3ebcb48ca472989b583cef5230f3e87d3f78fc6e552d9fb175495c449fdfd7e6bec
7
+ data.tar.gz: 5f01724b4123e60aeeb5b5a09668a67f7be6326d781ea5626a02e76d9966cc3fe63ab86d690b0e50937c874c8c656a7f17baf64e390e12bd12391e4e9ee282b8
@@ -133,7 +133,7 @@ ifndef::npm-readme[]
133
133
  === Ruby
134
134
 
135
135
  * 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+
136
+ * https://rubygems.org/gems/asciidoctor/[Asciidoctor] 1.5.7+
137
137
  * https://rubygems.org/gems/thread_safe/[thread_safe] (not required, but recommended for Ruby MRI)
138
138
 
139
139
 
@@ -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,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,29 +1,27 @@
1
- - unless id.nil?
2
- a id=id aria-hidden='true'
3
1
  - case type
4
2
  - when :emphasis
5
- em class=role =text
3
+ em id=id class=role =text
6
4
  - when :strong
7
- strong class=role =text
5
+ strong id=id class=role =text
8
6
  - when :monospaced
9
- code class=role =text
7
+ code id=id class=role =text
10
8
  - when :superscript
11
- sup class=role =text
9
+ sup id=id class=role =text
12
10
  - when :subscript
13
- sub class=role =text
11
+ sub id=id class=role =text
14
12
  - when :mark
15
- mark class=role =text
13
+ mark id=id class=role =text
16
14
  - when :double
17
- = html_tag_if role?, :span, :class=>role
15
+ = html_tag_if role? || id, :span, :id=>id, :class=>role
18
16
  =(double_quoted text)
19
17
  - when :single
20
- = html_tag_if role?, :span, :class=>role
18
+ = html_tag_if role? || id, :span, :id=>id, :class=>role
21
19
  =(single_quoted text)
22
20
  - when :asciimath, :latexmath
23
- span.math data-lang=stem_lang =(delimit_stem text, type)
21
+ span.math id=id data-lang=stem_lang =(delimit_stem text, type)
24
22
  - else
25
23
  - if role == 'line-through' || role == 'del'
26
- del =text
24
+ del id=id =text
27
25
  - else
28
- = html_tag_if role?, :span, :class=>role
26
+ = html_tag_if role? || id, :span, :id=>id, :class=>role
29
27
  =text
@@ -1,12 +1,16 @@
1
1
  = block_with_caption :top, :class=>'listing-block'
2
2
  - if style == 'source'
3
- - if highlighter == 'html-pipeline'
3
+ - highlighter = document.attr('source-highlighter')
4
+ / Asciidoctor >=2.0.0
5
+ - if defined?(::Asciidoctor::SyntaxHighlighter) && document.syntax_highlighter
6
+ = formatted_source
7
+ / Asciidoctor <2.0.0
8
+ - elsif highlighter == 'html-pipeline'
4
9
  pre: code data-lang=source_lang =content
5
10
  - else
6
- - unless highlighter == 'CodeRay'
7
- - code_class = "language-#{source_lang}" if source_lang
11
+ / The 1st and 3rd class element is for Asciidoctor <2.0.0
8
12
  pre class=[highlighter, 'highlight', ('linenums' if attr? :linenums), nowrap?]
9
- code class=code_class data-lang=source_lang =content
13
+ code class=source_code_class data-lang=source_lang =content
10
14
  - else
11
15
  pre class=nowrap? =content
12
16
  / Note: This is a hack to embed callout list into the listing element.
@@ -1,4 +1,4 @@
1
1
  = block_with_title :class=>['olist', style]
2
2
  ol class=style start=(attr :start) type=list_marker_keyword reversed=(option? 'reversed')
3
3
  - items.each do |item|
4
- li =(print_item_content item)
4
+ li id=item.id class=item.role =(print_item_content item)