diff --git a/config.ini b/config.ini index 8ea83812cccb9f44d124673f247679f10b52cf1a..a3029e070303d0ca16f7f1ae87ef7ab30bd0d6e6 100644 --- a/config.ini +++ b/config.ini @@ -29,7 +29,45 @@ combineCodeParagraphs = true ; Note, that the image caption has follow the image in the document. imageCaptions2AltText = true - +; Frontmatter configuration: +; The frontmatter option allows you to replace all content that appears before a specific +; heading in the generated markdown file with custom frontmatter content (such as YAML +; frontmatter for static site generators). This is useful when you want to add metadata, +; title, author information, or other structured content at the beginning of your markdown +; document instead of the original Word document content. +; +; Heading title that marks where frontmatter replacement should occur. +; The frontmatter will replace all content before this heading. The heading should include +; the markdown heading level (e.g., "# " for h1, "## " for h2, etc.). +frontmatterHeading = # Intellectual Property Rights +; +; Frontmatter to replace the content before the heading specified above. +; This can be used to add YAML frontmatter or other content at the start of the document. +; If not specified, the original content before the heading will be kept. +; +; Two ways to specify frontmatter: +; 1. Multiline string (subsequent lines must be indented): +; frontmatter = --- +; Title: "Document Title" +; Spec Number: "Author Name" +; --- +; +; 2. Read from file (use "file:" prefix): +; frontmatter = file:frontmatter.yaml +; +frontmatter = --- + Title: #TITLE# + Spec Number: #SPEC_NUMBER# + Version: #VERSION# + Date: #DATE# + Release: #RELEASE# + Work Item: #WORK-ITEM# + keywords: #KEYWORDS# + Copyright Year: #YEAR# + Long ISG Name: #LONG_ISG# + Short ISG Name: #SHORT_ISG# + --- +pandocTableWarnings = false [toc] ; Add section numbers to the headlines addSectionNumbers = false @@ -162,5 +200,5 @@ f0f3 = 266c743b2d3e [media] ; The following configurations specifies the cli command to convert a single .emf file to the.png and .svg image formats. ; If no conversion should or can be done, remove or comment the lines. -emfConverterPng = /Applications/LibreOffice.app/Contents/MacOS/soffice --headless --convert-to png "{infile}" --outdir "{outdir}" -emfConverterSvg = /Applications/LibreOffice.app/Contents/MacOS/soffice --headless --convert-to svg "{infile}" --outdir "{outdir}" +emfConverterPng = /usr/bin/soffice --headless --convert-to png "{infile}" --outdir "{outdir}" +emfConverterSvg = /usr/bin/soffice --headless --convert-to svg "{infile}" --outdir "{outdir}" diff --git a/spec2md.py b/spec2md.py index c2f9d581ec51e7f5d2fcbe129a63be814e6572ee..e464f8ca1052d2b618868fc4f6244ca41d9c65dd 100644 --- a/spec2md.py +++ b/spec2md.py @@ -153,6 +153,30 @@ class DocumentConfiguration(object): self.skipUnreferencedMediaFiles = config.getboolean('general', 'skipUnreferencedMediaFiles', fallback = False) self.imageCaptions2AltText = config.getboolean('general', 'imageCaptions2AltText', fallback = True) self.combineCodeParagraphs = config.getboolean('general', 'combineCodeParagraphs', fallback = True) + self.frontmatterHeading = config.get('general', 'frontmatterHeading', fallback = None) + + # Frontmatter - can be specified as multiline string or file path + # Note: ConfigParser supports multiline values if subsequent lines are indented + frontmatterConfig = config.get('general', 'frontmatter', fallback = None) + self.frontmatter = None + if frontmatterConfig: + if frontmatterConfig.startswith('file:'): + # Read frontmatter from file + frontmatterFile = frontmatterConfig[5:].strip() + frontmatterPath = Path(frontmatterFile) + if not frontmatterPath.is_absolute(): + # Relative to document directory or config file directory + docDir = os.path.split(documentFileName)[0] + frontmatterPath = Path(docDir) / frontmatterFile + try: + with open(frontmatterPath, 'r', encoding='utf-8') as f: + self.frontmatter = f.read().strip() + except Exception as e: + # Use print instead of _print since _print may not be available during config loading + print(f'Warning: Could not read frontmatter file "{frontmatterPath}": {e}') + else: + # Frontmatter specified directly in config (multiline supported) + self.frontmatter = frontmatterConfig.strip() # Paragraphs self.paragraphs = { c : config.getlist('paragraphs', c) # type: ignore [attr-defined] @@ -1030,6 +1054,27 @@ def processDocuments(documents:list[str], + # + # Replace content before configured heading with frontmatter if configured + # + if docConfig.frontmatter: + # Find the index of the configured heading + iprIndex = None + headingToFind = docConfig.frontmatterHeading.strip() + for i, line in enumerate(lines): + if line.strip() == headingToFind: + iprIndex = i + break + + if iprIndex is not None: + # Replace everything before the IPR section with frontmatter + frontmatterLines = docConfig.frontmatter.split('\n') + lines = frontmatterLines + [''] + lines[iprIndex:] + else: + # If IPR section not found, prepend to the beginning + frontmatterLines = docConfig.frontmatter.split('\n') + lines = frontmatterLines + [''] + lines + # # Write produced Markdown file #