diff --git a/.markdownlint.json b/.markdownlint.json new file mode 100644 index 000000000..f04743b5a --- /dev/null +++ b/.markdownlint.json @@ -0,0 +1,10 @@ +{ + "default": true, + "MD004": { "style": "asterisk"}, + "MD013": false, + "MD033": false, + "MD036": false, + "MD040": true, + "MD041": false, + "MD049": true +} diff --git a/conf.py b/conf.py index 729c97e81..8ad6bc01e 100644 --- a/conf.py +++ b/conf.py @@ -20,6 +20,17 @@ # import sys # sys.path.insert(0, os.path.abspath('.')) +import os +import subprocess +os.chdir(os.path.dirname(os.path.abspath(__file__))) + +# Clone the DIPs repository and process DIPs so they are rendered properly +if not os.path.exists('_external_repo'): + subprocess.check_call(['git', 'clone', 'https://github.com/dashpay/dips.git', '_dips']) + subprocess.check_call(['./scripts/dip-format.sh']) + subprocess.check_call('cd _dips/ && find . -name ".git" -prune -o -print -exec cp --parents \{} ../docs/core/dips/ \;', shell=True) + subprocess.check_call('cd', shell=True) + subprocess.check_call('rm -rf _dips/', shell=True) # -- General configuration ------------------------------------------------ diff --git a/scripts/dip-format.sh b/scripts/dip-format.sh new file mode 100755 index 000000000..adf640926 --- /dev/null +++ b/scripts/dip-format.sh @@ -0,0 +1,69 @@ +#!/bin/bash + +# Directory containing the files +dir='_dips' + +echo "Starting to process files in $dir..." + +# Add start of toctree +content=$(cat <> "$dir"/README.md + +for filename in "$dir"/*.md; do + if [ $(basename "$filename") = "README.md" ] + then + echo "Skipping README.md" + continue + fi + + echo "Processing $filename..." + + # Extract DIP number + full_dip_num=$(grep '^\s*DIP:' "$filename" | awk -F: '{print $2}' | sed 's/^ *//' | tr -d '\r') + dip="${full_dip_num#"${full_dip_num%%[!0]*}"}" + + # Extract title + title=$(grep '^\s*Title:' "$filename" | awk -F: '{print $2}' | sed 's/^ *//' | tr -d '\r') + + # Combine to make heading + heading="# $dip - $title" + echo "Heading $heading..." + + # Create temp file + tempfile=$(mktemp) + + # Write heading to temp file + echo -e "$heading\n" > "$tempfile" + + # Append original file contents to temp file + cat "$filename" >> "$tempfile" + + # Move temp file to original file + mv "$tempfile" "$filename" + + # Write the filename to the toctree + echo "dip-$full_dip_num" >> "$dir"/README.md +done + +# Close out the toctree +closing_content=$(cat <> "$dir"/README.md + +# Output the updated readme +cat "$dir"/README.md + +echo "Finished processing files."