#### [WSL (Windows Subsystem for Linux)](https://learn.microsoft.com/en-us/windows/wsl/install)
See additional setup steps in [section 1.2.1](#121-for-use-with-wsl).
### 1.1.3 Create a virtual environment
If you prefer to use Minconda or Pyenv, setup a virtual environment according to the following steps. If you are not using Miniconda or Pyenv, you can use any other python environment manger, just go to point 3 of the list and install the requirements using pip.
@@ -45,7 +51,7 @@ If you prefer to use Minconda or Pyenv, setup a virtual environment according to
1.`cd path/to/ETSI-GS-CIM-009`
2.`pip install -r requirements.txt`
### 1.1.2 Check Pandoc
### 1.1.4 Check Pandoc
Ensure Pandoc version **3.7.0.2** is installed.
@@ -73,6 +79,25 @@ Current folder
├── ETSIstyles.css
```
### 1.2.1 For Use with WSL
To ensure the script runs correctly with WSL 1[^1], do one of the following...
- Ensure the directory containing the script's files is saved in the Linux filesystem (ex., at `\\wsl$\{Distro}\home\{user}\path\to\script\dir`).
**OR**
- Ensure the current user has full control of the directory containing the script's files within the base Windows filesystem (ex., at `C:\path\to\script\dir`).
1. Right click on the top-level directory in the file explorer.
2. Click *Properties*
3. Go to the *Security* tab
4. Click *Edit* to modify permissions.
5. In the list, select the current user.
If the current user is not in the list, click *Add*. In the dialogue that opens, ensure that the *User* object type is selected and type the current user's username in the *Enter object names to select* box. Click *Check names*, then click *OK*.
6. Under *Permissions*, check the box for *Full control*, then click *Apply* and *OK*.
## 1.3 Expected Folder Structure after conversion
Through conversion you will eventually end up with the following folder structure:
@@ -130,7 +155,7 @@ The script `convert.py` handles the following conversions:
- If this argument is not provided, the source path will be _ETSI-GS-CIM-009_/_GENERATED_FILES_/_{value provided via `--folder`}_/_{value provided via `--frm`}_.
-`--file_order` - Provide the path to a JSON that contains the order in which user-created clauses and annexes should be.
- If this argument is not provided, the default ordering convention will be used. See [section 2.2.1.1](#2.2.1.1-preparation-create-markdown-from-scratch) for more details.
- If this argument is not provided, the default ordering convention will be used. See [section 2.2.1.1](#2211---preparation-create-markdown-from-scratch) for more details.
## 2.2 Conversion
@@ -154,7 +179,7 @@ Create Markdown from scratch or convert "dirty" HTML to "clean" Markdown
- Custom: Create a file ordering JSON according to the [template](./templates/json/file_order.json) and provide it to the script with the `--file_order` argument.
- In either case, if any other files that follow the naming convention *clause-{some text}* or *annex-{some text}* will be ordered alphabetically after the predefined files in the appropriate section of the document.
4. Create a *media* directory inside the directory created in step 1.
- As images are added to the Markdown, place the image in `PNG` and `EMF` form inside.[^1]
- As images are added to the Markdown, place the image in `PNG` and `EMF` form inside.[^2]
At this point, the document's clauses and annexes can be created. It is important to follow the following considerations to ensure the document is created properly:
- Ensure any files defined in a [file ordering JSON](./templates/json/file_order.json) are present in the source directory created in step 1, otherwise the script will print an error and quit prematurely.
@@ -224,4 +249,6 @@ Specify a different directory containing the HTML files.
`convert.py --frm html --to docx --folder {docname} --src relative/or/absolute/source/path`
[^1]:Method subject to change
[^1]:These steps may not be necessary with WSL 2, but it is recommended to follow them nevertheless.
"""Runs various checks on the Markdown file contents to ensure they are properly formatted. If any improper formatting is detected, display any fatal errors or warnings as necessary."""
defcheck_divs():
"""
### Display an error and exit when...
- An opening does not have a closing
### Display a warning when...
- The number of openings and number of closings do not match
- Find a closing without a corresponding opening, this is likely meant to be an opening and needs metadata
"""
i=0
in_div=False
in_div_no_metadata=(
False# For if/when a div is found that doesn't have any class
)
start_line_num=(
0# For keeping track of the line number at which the latest div was opened
)
# Keep track of numbers of div starts and div ends
# This div delineator doesn't have exactly three colons `:::`
print(
p_error(
f"{p_label(filename)}:{p_label(line_num)}: Improperly formatted div delineator in line. Line: {p_label(line)}"
)
)
raiseException("DIV_DELINEATOR_ERROR")
start_match=re.match(DIV_START_REGEX,line)
num_div_start+=1ifstart_matchelsenum_div_start
ifstart_match:
in_div_no_metadata=False# Set this to false in case it was true from a previous div without metadata
ifin_div:
# The previous div wasn't closed, print error and quit
print(
p_error(
f"{p_label(filename)}:{p_label(start_line_num)}: No end tag found for div starting at this line"
)
)
raiseException("DIV_DELINEATOR_ERROR")
else:
# A normal div opener
in_div=True
start_line_num=line_num
i+=1
continue
end_match=re.match(DIV_END_REGEX,line)
num_div_end+=1ifend_matchelsenum_div_end
ifend_match:
ifnotin_divandnotin_div_no_metadata:
# This should open a div, but it doesn't have a class assigned to it
print(
p_warning(
f"{p_label(filename)}:{p_label(line_num)}: The delineator at this line seems to open a div, this div or one before it may not be correctly structured."
### We need to run again the logic where we add the number in examples and notes since we might not have done it for all cases (it triggers on specific points, and if it happens the element is in the last heading/table it may be skipped)