-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0303af3
commit acfb4cf
Showing
8 changed files
with
188 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,4 +4,3 @@ node_modules | |
*.vsix | ||
*/**/__pycache__/* | ||
dist | ||
scripts |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,3 +8,4 @@ vsc-extension-quickstart.md | |
**/.eslintrc.json | ||
**/*.map | ||
**/*.ts | ||
dist/** |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import os | ||
from pathlib import Path | ||
|
||
project_dir = os.path.split(os.path.dirname(__file__))[0] | ||
project_dir_path = Path(project_dir) | ||
src_dir = os.path.join(project_dir, "src") | ||
src_dir_path = Path(src_dir) | ||
|
||
ch_src_dir = lambda: os.chdir(src_dir) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
from _dir import src_dir_path, project_dir_path | ||
import os | ||
from pathlib import Path | ||
import re | ||
import json | ||
|
||
SUBPACKAGES = ("rmarkdown-core", "bookdown", "blogdown") | ||
TITLE_PATTERN = re.compile(r"""__title__ = (["'`])([^\1]+?)\1""") | ||
PACKAGE_NAME = "rmarkdown_vscode" | ||
|
||
|
||
def main(): | ||
auto_ts = src_dir_path / "auto.ts" | ||
package_json_file = project_dir_path / "package.json" | ||
package_json_content = json.loads(package_json_file.read_text()) | ||
commands = package_json_content["contributes"]["commands"] | ||
commands_in_package_json = [c["command"] for c in commands] | ||
import_statements = "import * as vscode from 'vscode';" | ||
load_function = "export function loadCommands(context: vscode.ExtensionContext) {" | ||
for subpackage in SUBPACKAGES: | ||
subpackage_path = src_dir_path / subpackage | ||
commands_ts = subpackage_path.glob("commands/*.ts") | ||
for command_ts in commands_ts: | ||
command_name = command_ts.name[:-3] | ||
command_name_full = ".".join([PACKAGE_NAME, subpackage, command_name]) | ||
content = command_ts.read_text() | ||
TITLE = TITLE_PATTERN.findall(content)[0][1] | ||
|
||
if command_name_full not in commands_in_package_json: | ||
commands.append({"command": command_name_full, "title": TITLE}) | ||
|
||
x = next(c for c in commands if c["command"] == command_name_full) | ||
if x["title"] != TITLE: | ||
commands[commands.index(x)] = {"command": command_name_full,"title": TITLE} | ||
|
||
import_statements += f"import {{ {command_name} }} from './{command_ts.with_suffix('').relative_to(src_dir_path)}';" | ||
load_function += make_subscription_push(command_name_full, command_name) | ||
load_function += "}" | ||
|
||
package_json_file.write_text(json.dumps(package_json_content)) | ||
|
||
auto_ts.write_text(import_statements + load_function) | ||
|
||
|
||
def make_subscription_push(command_name_full, command_name): | ||
return ( | ||
'context.subscriptions.push(vscode.commands.registerCommand("' | ||
+ command_name_full | ||
+ '", () => { new ' | ||
+ command_name | ||
+ "().run();}));" | ||
) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
"""convert markdown syntax to rmarkdown syntax | ||
""" | ||
import re | ||
import json | ||
import os | ||
|
||
from toolz.functoolz import pipe | ||
|
||
from _dir import project_dir, project_dir_path | ||
|
||
|
||
def main(): | ||
syntaxes_dir_path = project_dir_path / "syntaxes" | ||
src_json = syntaxes_dir_path / "markdown.tmLanguage.json" | ||
dst_json = syntaxes_dir_path / "rmarkdown.tmLanguage.json" | ||
addition_json = syntaxes_dir_path / "addition.json" | ||
|
||
content = json.loads(src_json.read_text()) | ||
additions = json.loads(addition_json.read_text()) | ||
|
||
# content = conv_chunkparser(content) | ||
# add_new_with_context = lambda content: add_new(content, additions) | ||
content = pipe(content, conv_chunkparser) # , add_new_with_context) | ||
|
||
dst_json.write_text(json.dumps(content)) | ||
|
||
|
||
def conv_chunkparser(content): | ||
langAliases = {"js": "js|javascript|node"} | ||
for field, attrs in content["repository"].items(): | ||
if m := re.match(r"fenced_code_block_(\w+)", field): | ||
lang = m[1] | ||
if lang == "unknown": | ||
next | ||
engine = langAliases[lang] if langAliases.get(lang) else lang | ||
attrs["begin"] = r"(^|\G)(\s*)(```)\{(" + engine + r").*\}\s*$" | ||
attrs["end"] = r"(^|\G)(\2)(```)\s*$" | ||
if attrs["beginCaptures"].get("5"): | ||
del attrs["beginCaptures"]["5"] | ||
return content | ||
|
||
|
||
def add_new(content, additions: dict): | ||
entries: dict = content["repository"] | ||
for k, v in additions.items(): | ||
if k not in entries.keys(): | ||
entries.update({k: v}) | ||
extends = v["extends"] | ||
for e in entries.values(): | ||
if parent_includes := e.get("patterns"): | ||
includes = [ | ||
i["include"][1:] for i in parent_includes if i.get("include") | ||
] | ||
if (extends in includes) and (k not in includes): | ||
parent_includes.append({"include": f"#{k}"}) | ||
return content | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
"""make indexes e.g. from common/*.ts to common.ts | ||
""" | ||
import re | ||
import json | ||
import os | ||
from pathlib import Path | ||
|
||
TARGETS = ["common", "utils"] | ||
EXPORT_PATTERN = re.compile( | ||
r"^export.+(?:function|const|let|class|type|interface) (\w+)", re.MULTILINE | ||
) | ||
|
||
from _dir import src_dir | ||
|
||
|
||
def main(): | ||
for target in TARGETS: | ||
target_dir = Path(src_dir) / target | ||
target_ts = Path(src_dir) / f"{target}.ts" | ||
export_statement = "" | ||
for ts in target_dir.glob("*.ts"): | ||
content = ts.read_text() | ||
if exports := EXPORT_PATTERN.findall(content): | ||
export_statement += f"export {{ {', '.join(exports)} }} from './{target}/{ts.name[:-3]}';\n" | ||
target_ts.write_text(export_statement) | ||
|
||
# for ts in os.listdir(target): | ||
# if (not ts.endswith("ts")) or (ts[0] in [".", "_"]): | ||
# continue | ||
# with open(ts) as f: | ||
# content = f.read() | ||
# print(content) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
{ | ||
"include-graphics": { | ||
"captures": { | ||
"1": { | ||
"name": "punctuation.definition.link.markdown" | ||
}, | ||
"2": { | ||
"name": "punctuation.definition.link.markdown" | ||
}, | ||
"3": { | ||
"name": "punctuation.definition.link.markdown" | ||
}, | ||
"4": { | ||
"name": "markup.underline.link.image.markdown" | ||
}, | ||
"5": { | ||
"name": "punctuation.definition.link.markdown" | ||
}, | ||
"6": { "name": "punctuation.definition.link.markdown" } | ||
}, | ||
"match": "(?x) (include_graphics)(\\() (?P<quote>[\"']) ([^)]+) (\\g<quote>) (\\))", | ||
"name": "meta.image.inline.markdown", | ||
"extends": "image-inline" | ||
} | ||
} |