Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ If you want to use a different Crowdin project, store the project and file IDs i
- Required: `xliffPath` — path to the source XLIFF file; `mdPath` — path for the resulting Markdown file.
- Optional: `-u`/`--untranslated` — produce the untranslated version of the Markdown file.

- `md2xliff` - Convert a Markdown file to XLIFF.
- Required: `mdPath` — path to the Markdown file; `xliffPath` — path for the resulting XLIFF file.
- `md2html` - Convert a Markdown file to HTML.
- Required: `mdPath` — path to the Markdown file; `htmlPath` — path for the resulting HTML file.
- Optional: `-l`/`--lang` — language code (default: `en`); `-t`/`--docType` — document type, one of `userGuide`, `developerGuide`, `changes`, `keyCommands`.
Expand Down
8 changes: 8 additions & 0 deletions source/l10nUtil.py
Original file line number Diff line number Diff line change
Expand Up @@ -888,6 +888,9 @@ def main():
)
command_xliff2md.add_argument("xliffPath", help="Path to the xliff file")
command_xliff2md.add_argument("mdPath", help="Path to the resulting markdown file")
command_md2xliff = commands.add_parser("md2xliff", help="Convert markdown to xliff")
command_md2xliff.add_argument("mdPath", help="Path to the markdown file")
command_md2xliff.add_argument("xliffPath", help="Path to the resulting xliff file")
command_md2html = commands.add_parser("md2html", help="Convert markdown to html")
command_md2html.add_argument(
"-l",
Expand Down Expand Up @@ -1058,6 +1061,11 @@ def main():
outputPath=args.mdPath,
translated=not args.untranslated,
)
case "md2xliff":
markdownTranslate.generateXliff(
mdPath=args.mdPath,
outputPath=args.xliffPath,
)
case "md2html":
md2html.main(
source=args.mdPath,
Expand Down
32 changes: 27 additions & 5 deletions source/markdownTranslate.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
from dataclasses import dataclass
import subprocess

RAW_GITHUB_REPO_URL = "https://raw.githubusercontent.com/nvaccess/nvda"
re_kcTitle = re.compile(r"^(<!--\s+KC:title:\s*)(.+?)(\s*-->)$")
re_kcSettingsSection = re.compile(r"^(<!--\s+KC:settingsSection:\s*)(.+?)(\s*-->)$")
# Comments that span a single line in their entirety
Expand Down Expand Up @@ -90,11 +89,34 @@ def getGitDir() -> str:


def getRawGithubURLForPath(filePath: str) -> str:
rawGithubRepoURL = getGithubRepoURL()
gitDirPath = getGitDir()
commitID = getLastCommitID(filePath)
relativePath = os.path.relpath(os.path.abspath(filePath), gitDirPath)
Comment thread
seanbudd marked this conversation as resolved.
relativePath = relativePath.replace("\\", "/")
return f"{RAW_GITHUB_REPO_URL}/{commitID}/{relativePath}"
return f"{rawGithubRepoURL}/{commitID}/{relativePath}"


def getGithubRepoURL() -> str:
"""
Get the GitHub repository URL from git remote origin.
return: The raw GitHub URL for the repository.
"""
result = subprocess.run(
["git", "remote", "get-url", "origin"],
capture_output=True,
text=True,
check=True,
)
remote_url = result.stdout.strip()
# Convert SSH or HTTPS URL to raw GitHub URL format
if match := re.match(r"git@github\.com:(.+?)(?:\.git)?$", remote_url):
repo_path = match.group(1)
elif match := re.match(r"https://github\.com/(.+?)(?:\.git)?$", remote_url):
repo_path = match.group(1)
else:
raise ValueError(f"Cannot parse GitHub URL from git remote: {remote_url}")
return f"https://raw.githubusercontent.com/{repo_path}"


def preprocessMarkdownLines(mdLines: Iterable[str]) -> Iterable[str]:
Expand Down Expand Up @@ -611,9 +633,9 @@ def ensureMarkdownFilesMatch(path1: str, path2: str, allowBadAnchors: bool = Fal
line1 = m1.group(1) + m1.group(2)
line2 = m2.group(1) + m2.group(2)
if line1 != line2:
raise ValueError(
f"Files do not match at line {lineNo}: {line1=} {line2=}",
)
raise ValueError(
Comment thread
seanbudd marked this conversation as resolved.
Outdated
f"Files do not match at line {lineNo}: {line1=} {line2=}",
)
Comment thread
seanbudd marked this conversation as resolved.
Outdated
print("Files match")


Expand Down
Loading