diff options
Diffstat (limited to '')
14 files changed, 268 insertions, 0 deletions
diff --git a/docbook/asciidoctor-macros/README.adoc b/docbook/asciidoctor-macros/README.adoc new file mode 100644 index 00000000..cc5d64e5 --- /dev/null +++ b/docbook/asciidoctor-macros/README.adoc @@ -0,0 +1,5 @@ +Asciidoctor macros. + +These files are available under the MIT license to match the +https://github.com/asciidoctor/asciidoctor-extensions-lab[Asciidoctor Extensions Lab] +and Asciidoctor itself. diff --git a/docbook/asciidoctor-macros/commaize-block.rb b/docbook/asciidoctor-macros/commaize-block.rb new file mode 100644 index 00000000..aff6a3c1 --- /dev/null +++ b/docbook/asciidoctor-macros/commaize-block.rb @@ -0,0 +1,6 @@ +# SPDX-License-Identifier: MIT +RUBY_ENGINE == 'opal' ? (require 'commaize-block/extension') : (require_relative 'commaize-block/extension') + +Extensions.register do + block CommaizeBlock +end diff --git a/docbook/asciidoctor-macros/commaize-block/extension.rb b/docbook/asciidoctor-macros/commaize-block/extension.rb new file mode 100644 index 00000000..710f1a7e --- /dev/null +++ b/docbook/asciidoctor-macros/commaize-block/extension.rb @@ -0,0 +1,44 @@ +# SPDX-License-Identifier: MIT +require 'asciidoctor/extensions' unless RUBY_ENGINE == 'opal' + +include Asciidoctor + +# An extension that converts a list of lines to an inline Oxford comma-separated list. +# +# Usage +# +# [commaize] +# -- +# item1 +# item2 +# item3 +# -- +# +class CommaizeBlock < Extensions::BlockProcessor + include WsUtils + use_dsl + + named :commaize + on_contexts :paragraph, :open + # XXX What's the difference between text, raw, simple, verbatim, etc? + parse_content_as :simple + + def process(parent, reader, attrs) + lines = reader.lines + sort = attrs.fetch('sort', 'true') == 'true' + + lines = lines.reject(&:empty?) + lines = lines.map(&:strip) + lines = lines.sort_by(&:downcase) if sort + + if lines.length < 2 + create_paragraph parent, lines, attrs + elsif lines.length == 2 + create_paragraph parent, lines.join(" and "), attrs + else + commaized = lines[0..-2].join(", ") + commaized << ", and " + lines[-1] + create_paragraph parent, commaized, attrs + end + end +end diff --git a/docbook/asciidoctor-macros/commaize-block/sample.adoc b/docbook/asciidoctor-macros/commaize-block/sample.adoc new file mode 100644 index 00000000..9cb2e1ec --- /dev/null +++ b/docbook/asciidoctor-macros/commaize-block/sample.adoc @@ -0,0 +1,31 @@ += Sorted, delimited, empty lines + +[commaize] +-- +One +two + +red + +blue +Fish +-- + += Unsorted + +[commaize, sort=false] +One +two +red +blue +Fish + += Two elements + +[commaize] +One +Two + += One element +[commaize] +Just the one diff --git a/docbook/asciidoctor-macros/cveidlink-inline-macro.rb b/docbook/asciidoctor-macros/cveidlink-inline-macro.rb new file mode 100644 index 00000000..beb19a3b --- /dev/null +++ b/docbook/asciidoctor-macros/cveidlink-inline-macro.rb @@ -0,0 +1,8 @@ +# SPDX-License-Identifier: MIT +# Copied from https://github.com/asciidoctor/asciidoctor-extensions-lab/blob/master/lib/man-inline-macro.rb + +RUBY_ENGINE == 'opal' ? (require 'cveidlink-inline-macro/extension') : (require_relative 'cveidlink-inline-macro/extension') + +Extensions.register do + inline_macro CVEIdLinkInlineMacro +end diff --git a/docbook/asciidoctor-macros/cveidlink-inline-macro/extension.rb b/docbook/asciidoctor-macros/cveidlink-inline-macro/extension.rb new file mode 100644 index 00000000..2dec88da --- /dev/null +++ b/docbook/asciidoctor-macros/cveidlink-inline-macro/extension.rb @@ -0,0 +1,24 @@ +# SPDX-License-Identifier: MIT +require 'asciidoctor/extensions' unless RUBY_ENGINE == 'opal' + +include ::Asciidoctor + +# An inline macro that generates a link to a CVE Record identified by its CVE +# Number. +# +# Usage +# +# cveidlink:<cve-number>[] +# +class CVEIdLinkInlineMacro < Extensions::InlineMacroProcessor + include WsUtils + use_dsl + + named :cveidlink + + def process(parent, cvenum, _attrs) + cvename = "CVE-#{cvenum}" + target = %(https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-#{cvenum}) + create_doc_links(parent, target, cvename) + end +end diff --git a/docbook/asciidoctor-macros/manarg-block.rb b/docbook/asciidoctor-macros/manarg-block.rb new file mode 100644 index 00000000..07a9bf26 --- /dev/null +++ b/docbook/asciidoctor-macros/manarg-block.rb @@ -0,0 +1,8 @@ +# SPDX-License-Identifier: MIT +# Adapted from https://github.com/asciidoctor/asciidoctor-extensions-lab/blob/master/lib/man-inline-macro.rb + +RUBY_ENGINE == 'opal' ? (require 'manarg-block/extension') : (require_relative 'manarg-block/extension') + +Extensions.register do + block ManArgBlock +end diff --git a/docbook/asciidoctor-macros/manarg-block/extension.rb b/docbook/asciidoctor-macros/manarg-block/extension.rb new file mode 100644 index 00000000..2461e723 --- /dev/null +++ b/docbook/asciidoctor-macros/manarg-block/extension.rb @@ -0,0 +1,45 @@ +# SPDX-License-Identifier: MIT +require 'asciidoctor/extensions' unless RUBY_ENGINE == 'opal' + +include Asciidoctor + +# An inline macro that generates markup for man page arguments. +# Adapted from https://github.com/asciidoctor/asciidoctor-extensions-lab/blob/master/lib/man-inline-macro.rb +# +# Usage: +# +# [manarg] +# *command* +# [ *--help* ] +# [ *--flash-lights* ] +# +class ManArgBlock < Extensions::BlockProcessor + use_dsl + + named :manarg + parse_content_as :simple + + def process parent, reader, attrs + nowrap_lines = reader.readlines.map {|line| + if parent.document.basebackend? 'html' + # Apply the custom style "[.nowrap]## ... ##" to each line. + # This generates "<span content="nowrap"> ... </span>". Pass + # each '#' through for extra paranoia. + %([.nowrap]###{line.gsub('#', '+++#+++')}##) + elsif parent.document.backend == 'manpage' + # Replace spaces with non-breaking spaces (' '), then make + # bold markup unconstrained ('*' -> '**'). For now we naively + # assume that bolds are always constrained (that is, we only + # have single '*'s). We *should* be able to do this properly + # with a regex, but for some reason + # gsub(/([^*])\*([^*])/, '\1**\2') + # doesn't match the first asterisk in "*--extcap-interface*=<interface>" + %(#{line.gsub(' ', ' ').gsub('*', '**')}) + else + line + end + } + # STDERR.puts(nowrap_lines) + create_paragraph parent, nowrap_lines, attrs + end +end diff --git a/docbook/asciidoctor-macros/manarg-block/sample.adoc b/docbook/asciidoctor-macros/manarg-block/sample.adoc new file mode 100644 index 00000000..5b4a4019 --- /dev/null +++ b/docbook/asciidoctor-macros/manarg-block/sample.adoc @@ -0,0 +1,19 @@ += androiddump(1) +:doctype: manpage + +== NAME + +sample - Sample man page + +== SYNOPSIS + +[manarg] +*androiddump* +*--mandatory-argument +[ *--optional-argument* ] +*--complex-mandatory*=<argument> +[ *--complex-optional*=<argument> ] + +== DESCRIPTION + +Sample man page. diff --git a/docbook/asciidoctor-macros/ws_utils.rb b/docbook/asciidoctor-macros/ws_utils.rb new file mode 100644 index 00000000..9a4551a0 --- /dev/null +++ b/docbook/asciidoctor-macros/ws_utils.rb @@ -0,0 +1,13 @@ +# SPDX-License-Identifier: MIT +module WsUtils + def create_doc_links(parent, target, text) + if (parent.document.basebackend? 'docbook') || (parent.document.basebackend? 'html') + parent.document.register :links, target + create_anchor(parent, text, type: :link, target: target).render.to_s + elsif parent.document.backend == 'manpage' + "\\fB#{text}" + else + text + end + end +end diff --git a/docbook/asciidoctor-macros/wsbuglink-inline-macro.rb b/docbook/asciidoctor-macros/wsbuglink-inline-macro.rb new file mode 100644 index 00000000..3f192aab --- /dev/null +++ b/docbook/asciidoctor-macros/wsbuglink-inline-macro.rb @@ -0,0 +1,8 @@ +# SPDX-License-Identifier: MIT +# Copied from https://github.com/asciidoctor/asciidoctor-extensions-lab/blob/master/lib/man-inline-macro.rb + +RUBY_ENGINE == 'opal' ? (require 'wsbuglink-inline-macro/extension') : (require_relative 'wsbuglink-inline-macro/extension') + +Extensions.register do + inline_macro WSBugLinkInlineMacro +end diff --git a/docbook/asciidoctor-macros/wsbuglink-inline-macro/extension.rb b/docbook/asciidoctor-macros/wsbuglink-inline-macro/extension.rb new file mode 100644 index 00000000..6cdb665b --- /dev/null +++ b/docbook/asciidoctor-macros/wsbuglink-inline-macro/extension.rb @@ -0,0 +1,26 @@ +# SPDX-License-Identifier: MIT +require 'asciidoctor/extensions' unless RUBY_ENGINE == 'opal' + +include ::Asciidoctor + +# An inline macro that generates a link to a Wireshark bug report. +# +# Usage +# +# wsbuglink:<number>[<issue text>] +# Default bug text is "Issue <number>". +# +class WSBugLinkInlineMacro < Extensions::InlineMacroProcessor + include WsUtils + use_dsl + + named :wsbuglink + parse_content_as :text + name_positional_attributes 'bugtext' + + def process(parent, issueid, attrs) + bugtext = attrs['bugtext'] || %(Issue #{issueid}) + target = %(https://gitlab.com/wireshark/wireshark/-/issues/#{issueid}) + create_doc_links(parent, target, bugtext) + end +end diff --git a/docbook/asciidoctor-macros/wssalink-inline-macro.rb b/docbook/asciidoctor-macros/wssalink-inline-macro.rb new file mode 100644 index 00000000..3172ea50 --- /dev/null +++ b/docbook/asciidoctor-macros/wssalink-inline-macro.rb @@ -0,0 +1,8 @@ +# SPDX-License-Identifier: MIT +# Copied from https://github.com/asciidoctor/asciidoctor-extensions-lab/blob/master/lib/man-inline-macro.rb + +RUBY_ENGINE == 'opal' ? (require 'wssalink-inline-macro/extension') : (require_relative 'wssalink-inline-macro/extension') + +Extensions.register do + inline_macro WSSALinkInlineMacro +end diff --git a/docbook/asciidoctor-macros/wssalink-inline-macro/extension.rb b/docbook/asciidoctor-macros/wssalink-inline-macro/extension.rb new file mode 100644 index 00000000..3af9c8f3 --- /dev/null +++ b/docbook/asciidoctor-macros/wssalink-inline-macro/extension.rb @@ -0,0 +1,23 @@ +# SPDX-License-Identifier: MIT +require 'asciidoctor/extensions' unless RUBY_ENGINE == 'opal' + +include ::Asciidoctor + +# An inline macro that generates a link to a Wireshark Security Advisory. +# +# Usage +# +# wssalink:<dddd>[] +# +class WSSALinkInlineMacro < Extensions::InlineMacroProcessor + include WsUtils + use_dsl + + named :'wssalink' + + def process(parent, sanum, attrs) + satext = "wnpa-sec-#{sanum}" + target = %(https://www.wireshark.org/security/wnpa-sec-#{sanum}) + create_doc_links(parent, target, satext) + end +end |