/******************************************************************************/ /* */ /* RexxPubOptions.cls -- Shared option handling for RexxPub pipelines */ /* ================================================================= */ /* */ /* This file is part of the Rexx Parser package */ /* [See https://rexx.epbcn.com/rexx-parser/] */ /* */ /* Copyright (c) 2024-2026 Josep Maria Blasco */ /* */ /* License: Apache License 2.0 (https://www.apache.org/licenses/LICENSE-2.0) */ /* */ /* Version history: */ /* */ /* Date Version Details */ /* -------- ------- --------------------------------------------------------- */ /* 20260313 0.5 Created: refactor common code from CGI, md2pdf, md2html */ /* */ /******************************************************************************/ ::Requires "ANSI.ErrorText.cls" /******************************************************************************/ /* */ /* ParseRexxPubYAML(yaml) -- Extract RexxPub options from parsed YAML */ /* */ /* 'yaml' is the StringTable returned by YAMLFrontMatter(), or .nil. */ /* */ /* Returns a StringTable with normalized option values: */ /* */ /* Top-level (from rexxpub: block): */ /* style - Rexx highlighting style (or .Nil if not set) */ /* size - base font size (or .Nil if not set) */ /* section-numbers - numbering depth (or .Nil if not set) */ /* number-figures - 0 or 1 (or .Nil if not set) */ /* docclass - document class name (or .Nil if not set) */ /* outline - PDF bookmark depth (or .Nil if not set) */ /* */ /* Listing sub-options (from rexxpub: listings:): */ /* listing-caption-position - "above" or "below" (default: "above") */ /* listing-caption-style - "normal" or "italic" (default: "normal") */ /* listing-label-style - "bold", "italic", etc. (default: "bold") */ /* listing-label - custom label text (default: "") */ /* listing-frame - "none", "tb", "single", "leftbar" */ /* (default: "none") */ /* */ /* Figure sub-options (from rexxpub: figures:): */ /* figure-caption-position - "above" or "below" (default: "below") */ /* figure-caption-style - "normal" or "italic" (default: "normal") */ /* figure-label-style - "bold", "italic", etc. (default: "bold") */ /* figure-label - custom label text (default: "") */ /* */ /* Pandoc metadata (from top-level YAML): */ /* language - HTML lang attribute (Pandoc variable */ /* 'lang'; or .Nil if not set) */ /* highlight-style - Pandoc highlighting theme */ /* (or .Nil if not set) */ /* */ /******************************************************************************/ ::Routine ParseRexxPubYAML Public Use Strict Arg yaml opts = .StringTable~new -- Top-level defaults (.Nil = "not set by YAML") opts["style"] = .Nil opts["size"] = .Nil opts["section-numbers"] = .Nil opts["number-figures"] = .Nil opts["docclass"] = .Nil opts["language"] = .Nil opts["outline"] = .Nil opts["chapter"] = .Nil -- Listing sub-option defaults opts["listing-caption-position"] = "above" opts["listing-caption-style"] = "normal" opts["listing-label-style"] = "bold" opts["listing-label"] = "" opts["listing-frame"] = "none" -- Figure sub-option defaults opts["figure-caption-position"] = "below" opts["figure-caption-style"] = "normal" opts["figure-label-style"] = "bold" opts["figure-label"] = "" -- Pandoc metadata (.Nil = "not set by YAML") opts["highlight-style"] = .Nil If yaml == .Nil Then Return opts -- Process first-level entries -- Read highlight-style from top-level YAML (standard Pandoc metadata) If yaml~hasIndex("highlight-style") Then opts["highlight-style"] = Lower(yaml["highlight-style"]) -- Read lang from top-level YAML (standard Pandoc metadata). -- Stored internally as "language" for historical reasons. If yaml~hasIndex("lang") Then opts["language"] = yaml["lang"] -- Process second- and third-level entries If yaml~hasIndex("rexxpub") Then Call ReadRexxPubBlock Return opts ConditionalCopyFrom: Procedure Expose opts prefix Use Arg table, key, lowerCase = 0, list = "" newValue = table[key] If newValue == .Nil Then Return If lowerCase Then newValue = Lower(newValue) If list \== "", WordPos(newValue, list) == 0 Then Return newKey = key If prefix \== "" Then newKey = prefix"-"key If table~hasIndex(key) Then opts[newKey] = newValue Return ReadRexxPubBlock: -- Read rexxpub: block rp = yaml["rexxpub"] If \rp~isA(.StringTable) Then Return lowerCase = 1 prefix = "" -- Process second-level entries Call ConditionalCopyFrom rp, "style" Call ConditionalCopyFrom rp, "size" Call ConditionalCopyFrom rp, "section-numbers" Call ConditionalCopyFrom rp, "number-figures" , lowerCase Call ConditionalCopyFrom rp, "docclass" , lowerCase Call ConditionalCopyFrom rp, "outline" Call ConditionalCopyFrom rp, "chapter" -- Sanitize values opt = opts["number-figures"] If opt \== .Nil Then Do Select Case opt When 0, 1 Then Nop When "true" Then opts["number-figures"] = 1 When "false" Then opts["number-figures"] = 0 Otherwise opts~remove("number-figures") End End outline = opts["outline"] If DataType(outline,"W"), outline >= 0, outline <= 6 Then Nop Else opts~remove("outline") -- Process third-level entries -- listings: sub-table If rp~hasIndex("listings") Then Call ProcessListings -- figures: sub-table If rp~hasIndex("figures") Then Call ProcessFigures Return ProcessListings: lst = rp["listings"] If \lst~isA(.StringTable) Then Return prefix = "listing" Call ConditionalCopyFrom lst, "caption-position", lowerCase, "above below" Call ConditionalCopyFrom lst, "caption-style", lowerCase, "normal italic" Call ConditionalCopyFrom lst, "label-style", lowerCase, - "normal bold italic bold-italic" Call ConditionalCopyFrom lst, "frame", lowerCase, - "none tb single leftbar" Call ConditionalCopyFrom lst, "label" Return ProcessFigures: fig = rp["figures"] If \fig~isA(.StringTable) Then Return prefix = "figure" Call ConditionalCopyFrom fig, "caption-position", lowerCase, "above below" Call ConditionalCopyFrom fig, "caption-style", lowerCase, "normal italic" Call ConditionalCopyFrom fig, "label-style", lowerCase, - "normal bold italic bold-italic" Call ConditionalCopyFrom fig, "label" Return /******************************************************************************/ /* */ /* BuildCaptionOverrides(opts) -- Generate CSS override string */ /* */ /* 'opts' is the StringTable returned by ParseRexxPubYAML(). */ /* */ /* Returns a StringTable with three keys: */ /* "overrideCSS" - CSS rules to inject as a