Skip to content

Commit e06c1dc

Browse files
committed
update to version 0.0.2
1. headings.md document added for easy review of the output file structure 2. generate_patterns.py script added for parsing the headings.md to generate the patterns.json
1 parent d7e1bc6 commit e06c1dc

File tree

6 files changed

+843
-144
lines changed

6 files changed

+843
-144
lines changed

extension.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ const fs = require('fs');
33
const path = require('path');
44

55
// Synchronously read orcaPatterns.json
6-
const orcaPatterns = JSON.parse(fs.readFileSync(path.join(__dirname, 'orcaPatterns.json'), 'utf8'));
6+
const orcaPatterns = JSON.parse(fs.readFileSync(path.join(__dirname, 'patterns.json'), 'utf8'));
77

88
// Adjust regex patterns to RegExp objects
99
orcaPatterns.forEach(pattern => {

generate_patterns.py

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import re
2+
import json
3+
4+
def extract_info(markdown_content):
5+
lines = markdown_content.split("\n")
6+
sections = []
7+
current_section = []
8+
9+
# Split lines into sections based on headings
10+
for line in lines:
11+
if line.startswith("##"):
12+
if current_section:
13+
sections.append("\n".join(current_section))
14+
current_section = []
15+
current_section.append(line)
16+
17+
# Ensure the last section is also included
18+
if current_section:
19+
sections.append("\n".join(current_section))
20+
21+
extracted_data = []
22+
23+
for section in sections:
24+
title = re.search(r"^#* (.+)", section)
25+
if not title:
26+
continue
27+
28+
title = title.group(1)
29+
level = re.search(r"Heading level: (\d+)", section)
30+
regex = re.search(r"Regular expression:\n\n```plaintext\n(.*?)\n```", section, re.DOTALL)
31+
visibility = re.search(r"Visiblity: (\w+)", section)
32+
33+
if not (level and regex and visibility):
34+
continue
35+
36+
level = int(level.group(1))
37+
regex = regex.group(1).strip()
38+
visibility = visibility.group(1).strip()
39+
40+
if visibility == "show":
41+
extracted_data.append({
42+
"regex": regex.replace("\\\\", "\\"),
43+
"level": level,
44+
"title": title
45+
})
46+
47+
return extracted_data
48+
49+
with open("headings.md", "r") as f:
50+
markdown_content = f.read()
51+
52+
with open("patterns.json", "w") as f:
53+
json.dump(extract_info(markdown_content), f, indent=4)

0 commit comments

Comments
 (0)