diff options
| author | nsfisis <nsfisis@gmail.com> | 2022-11-19 14:23:32 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2022-11-19 14:25:59 +0900 |
| commit | 6209453817da9922f28bac1bb1522c6d380630ab (patch) | |
| tree | 19e0699e751af387d549d6720ca215c8065b3c0c /lib/parser.rb | |
| parent | 0cafa073914b5e0b162b735a7f8445fb2aa8a604 (diff) | |
| download | blog.nsfisis.dev-6209453817da9922f28bac1bb1522c6d380630ab.tar.gz blog.nsfisis.dev-6209453817da9922f28bac1bb1522c6d380630ab.tar.zst blog.nsfisis.dev-6209453817da9922f28bac1bb1522c6d380630ab.zip | |
Hugo to Asciidoctor
Diffstat (limited to 'lib/parser.rb')
| -rw-r--r-- | lib/parser.rb | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/lib/parser.rb b/lib/parser.rb new file mode 100644 index 0000000..8ae3303 --- /dev/null +++ b/lib/parser.rb @@ -0,0 +1,54 @@ +module NulDoc + class Parser + def initialize(common_attributes, content_dir, template_dir) + @common_attributes = common_attributes + @content_dir = content_dir + @template_dir = template_dir + end + + def parse_file(file_path) + Asciidoctor.load_file( + file_path, + backend: :html5, + doctype: :article, + standalone: true, + safe: :unsafe, + template_dirs: [@template_dir], + template_engine: 'erb', + attributes: @common_attributes.merge({ + 'source-file-path' => file_path, + 'href' => file_path.sub(@content_dir, '').sub('.adoc', '/'), + }), + extension_registry: Asciidoctor::Extensions.create do + tree_processor Nuldoc::Extensions::RevisionHistoryProcessor + tree_processor Nuldoc::Extensions::DocumentTitleProcessor + tree_processor Nuldoc::Extensions::LangAttributeProcessor + # tree_processor Nuldoc::Extensions::SectionIdValidator + # tree_processor Nuldoc::Extensions::SourceIdValidator + tree_processor Nuldoc::Extensions::TagsProcessor + + # MUST BE AT THE END + tree_processor Nuldoc::Extensions::SourceIdProcessor + end, + ) + end + + def parse_string(s, copyright_year) + Asciidoctor.convert( + s, + backend: :html5, + doctype: :article, + safe: :unsafe, + template_dirs: [@template_dir], + template_engine: 'erb', + attributes: @common_attributes.merge({ + 'copyright-year' => copyright_year, + }), + extension_registry: Asciidoctor::Extensions.create do + tree_processor Nuldoc::Extensions::LangAttributeProcessor + tree_processor Nuldoc::Extensions::TagsProcessor + end, + ) + end + end +end |
