Skip to content

Erroneous translation of Trac-style links to Markdown inside code blocks #29

@tbeu

Description

@tbeu

The following code in translate_markup

    // Translate Trac-style links to Markdown
    $data = preg_replace('/\[([^ ]+) ([^\]]+)\]/', '[$2]($1)', $data);

should not be applied inside a code block.

Example file: mo.txt
Example code for easy reproduction:

<?php

$data = file_get_contents("mo.txt");

file_put_contents("gh.txt", translate_markup($data));

function translate_markup($data) {
    // Replace code blocks with an associated language
    $data = preg_replace('/\{\{\{(\s*#!(\w+))?/m', '```$2', $data);
    $data = preg_replace('/\}\}\}/', '```', $data);

    // Avoid non-ASCII characters, as that will cause trouble with json_encode()
    $data = preg_replace('/[^(\x00-\x7F)]*/','', $data);

    // Translate Trac-style links to Markdown
    $data = preg_replace('/\[([^ ]+) ([^\]]+)\]/', '[$2]($1)', $data);

    // Possibly translate other markup as well?
    return $data;
}

?>

mo.txt

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions