Commit 6b5d4521 authored by Naum Spaseski's avatar Naum Spaseski Committed by Miguel Angel Reina Ortega
Browse files

Added optional frontmatter header

parent c7254b09
Loading
Loading
Loading
Loading
+39 −0
Original line number Diff line number Diff line
@@ -29,6 +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 = ---
;    frontmatter = title: "Document Title"
;    frontmatter = author: "Author Name"
;    frontmatter = date: "2025-01-01"
;    frontmatter = ---
;
; 2. Read from file (use "file:" prefix):
;    frontmatter = file:frontmatter.yaml
;
frontmatter = ---
	Title: Network Functions Virtualisation (NFV);<br>Protocols and Data Models;<br>NFV-MANO procedures specification
	Spec Number: NFV-SOL 016
	Version: v5.2.3
	Date: 2025-11
	Release: 5
	Work Item: RGS/NFV-SOL016
	keywords: management, MANO, NFV, procedure
	Copyright Year: 2025
	Long ISG Name: Network Functions Virtualisation
	Short ISG Name: NFV
	---

[toc]
; Add section numbers to the headlines
+45 −0
Original line number Diff line number Diff line
@@ -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
			#