Commit 6401024d authored by ankraft's avatar ankraft
Browse files

Merged additional changes from original GitHub repo

parent 78951d3f
Loading
Loading
Loading
Loading
+16 −1
Original line number Original line Diff line number Diff line
@@ -26,6 +26,21 @@ python3 spec2md.py <path-to-word-document>


Is *LibreOffice* already running? If yes, then close it.
Is *LibreOffice* already running? If yes, then close it.



### Does the converter generate links to tables?

If the table caption starts with "Table " and has a ":" after the table number then an HTML anchor with that number 
is appended to the converted table caption. The anchor name is "table_\<table number>. This anchor can be used to link to the table, for example:

```markdown
[foo](#table_7.2.4-1)

or

<a href="#table_7.2.4-1">bar</a>
```


### Are linebreaks, paragraphs, and lists supported in table cells?
### Are linebreaks, paragraphs, and lists supported in table cells?


Unfortunately, markdown doesn't support multiple paragraphs in table cells. A table cell must be a single line. However, one can add a html `<br />` linebreak to break between lines:
Unfortunately, markdown doesn't support multiple paragraphs in table cells. A table cell must be a single line. However, one can add a html `<br />` linebreak to break between lines:
+5 −3
Original line number Original line Diff line number Diff line
@@ -12,9 +12,11 @@ markdown-it-py==3.0.0
    # via rich
    # via rich
mdurl==0.1.2
mdurl==0.1.2
    # via markdown-it-py
    # via markdown-it-py
pygments==2.15.1
pygments==2.17.2
    # via rich
    # via rich
python-docx==0.8.11
python-docx==1.1.0
    # via oneM2M-spec-2-MD-converter (setup.py)
    # via oneM2M-spec-2-MD-converter (setup.py)
rich==13.4.2
rich==13.7.0
    # via oneM2M-spec-2-MD-converter (setup.py)
    # via oneM2M-spec-2-MD-converter (setup.py)
typing-extensions==4.8.0
    # via python-docx
+18 −5
Original line number Original line Diff line number Diff line
@@ -89,7 +89,7 @@ class SectionNumbers(object):
		self.annex:int = 64
		self.annex:int = 64


		
		
	def nextSectionNumber(self, level:int, isAnnex:bool = False) -> str:
	def nextSectionNumber(self, level:int, isAnnex:Optional[bool] = False) -> str:
		if isAnnex:
		if isAnnex:
			self.levels[0] = self.annex
			self.levels[0] = self.annex
		else:
		else:
@@ -190,7 +190,7 @@ class DocumentConfiguration(object):
		self.characters = { int(c, 16) : binascii.unhexlify(config.get('characters', c)).decode('utf-8')	# type: ignore [attr-defined]
		self.characters = { int(c, 16) : binascii.unhexlify(config.get('characters', c)).decode('utf-8')	# type: ignore [attr-defined]
							for c in config['characters'] }
							for c in config['characters'] }


		# Media
		# Media & Converter
		self.emfConverterPng = config.get('media', 'emfConverterPng', fallback = None)
		self.emfConverterPng = config.get('media', 'emfConverterPng', fallback = None)
		self.emfConverterSvg = config.get('media', 'emfConverterSvg', fallback = None)
		self.emfConverterSvg = config.get('media', 'emfConverterSvg', fallback = None)


@@ -401,6 +401,15 @@ def processDocuments(documents:list[str], outDirectory:str, skipImageConversion:
						_print(f'[yellow]{_symError}')
						_print(f'[yellow]{_symError}')
						_result += f'<mark>{_symError}</mark>'
						_result += f'<mark>{_symError}</mark>'


					# ignore deleted test
					case 'del':
						pass

					# try to keep the text of inserted text
					case 'ins':
						for x in element:
							_result += _parseXML(x)
					
					case _ if tag in _ignoredTags:	# ignore
					case _ if tag in _ignoredTags:	# ignore
						pass
						pass
					
					
@@ -606,6 +615,8 @@ def processDocuments(documents:list[str], outDirectory:str, skipImageConversion:
						elif style in docConfig.tablecaption:
						elif style in docConfig.tablecaption:
							lines.append('')
							lines.append('')
							lines.append(f'**{replaceNL(text).strip()}**')
							lines.append(f'**{replaceNL(text).strip()}**')
							anchor = f'<a name="table_{caption[6:].split(":")[0].strip()}"></a>' if caption.startswith('Table ') and ':' in caption else ''
							lines.append(f'**{caption}**{anchor}')
							
							
						#	Image Caption
						#	Image Caption
						elif style in docConfig.imagecaption:
						elif style in docConfig.imagecaption:
@@ -775,14 +786,14 @@ def processDocuments(documents:list[str], outDirectory:str, skipImageConversion:
			#	Convert media files
			#	Convert media files
			#
			#


			def _convertImage(converter:str, format:str):
			def _convertImage(converter:str, format:str) -> None:
				if converter:
				if converter:
					for fn in list(emfFiles):
					for fn in list(emfFiles):
						_f = Path(fn)		# Filename to handle
						_f = Path(fn)		# Filename to handle
						_t = imageDirName	# Target directory
						_t = imageDirName	# Target directory
						if _f.stem not in referencedImages:
						if _f.stem not in referencedImages:
							if not fn.startswith(unreferencedDirName):
							if not fn.startswith(unreferencedDirName):
								_print(f'[red]Unreferenced image: {PurePath(fn).name} {"(skipped)" if docConfig.skipUnreferencedMediaFiles else ""}', highlight = False)
								_print(f'[yellow]Unreferenced image in the document: {PurePath(fn).name} {"(skipped)" if docConfig.skipUnreferencedMediaFiles else ""}', highlight = False)
								_print(f'[yellow]Moving image file to: {unreferencedDirName}', highlight = False)
								_print(f'[yellow]Moving image file to: {unreferencedDirName}', highlight = False)
								_n = f'{unreferencedDirName}/{_f.name}'
								_n = f'{unreferencedDirName}/{_f.name}'
								_p = _f.replace(_n)
								_p = _f.replace(_n)
@@ -797,6 +808,8 @@ def processDocuments(documents:list[str], outDirectory:str, skipImageConversion:
						_print(f'Converting EMF file: {fn} to "{format}"', highlight = False)
						_print(f'Converting EMF file: {fn} to "{format}"', highlight = False)
						if (res := subprocess.run(cmd, shell = True, capture_output = True)).returncode != 0:
						if (res := subprocess.run(cmd, shell = True, capture_output = True)).returncode != 0:
							_print(f'[red]Error running command: {res.stderr.decode("utf-8")}')
							_print(f'[red]Error running command: {res.stderr.decode("utf-8")}')
							_print(f'[red]Please check the configuration file -> section "\[media]" for the converter command: {converter}')
							break


			if not skipImageConversion:
			if not skipImageConversion:
				if docConfig.emfConverterPng:
				if docConfig.emfConverterPng: