<commit_before>/*
 * Copyright (C) 2012-2017  Online-Go.com
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as
 * published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

import * as React from "react";
import * as commonmark from "commonmark";

interface MarkdownProps {
    source: string;
}

let parser = new commonmark.Parser();
let renderer = new commonmark.HtmlRenderer();

export class Markdown extends React.PureComponent<MarkdownProps, {html}> {
    constructor(props) {
        super(props);
        this.state = {
            html: this.props.source ? renderer.render(parser.parse(this.massage(this.props.source))) : ""
        };
    }

    massage(source: string): string {
        source = source.replace(/^(#+)([a-zA-Z0-9])/g, "$1 $2"); // headers used to behave like this
        source = source.replace(/<script/ig, "(script"); // hasnt' been exploitable yet with how react works i don't think, but they leave most html intact for some stupid reason, this string shouldn't exist anyways
        return source;
    }

    componentWillReceiveProps(next_props) {{{
        if (next_props.source !== this.props.source) {
            this.setState({
                html: next_props.source ? renderer.render(parser.parse(this.massage(next_props.source))) : ""
            });
        }
    }}}

    render() {
        return (<commit_msg>Support plain links in our markdown system<commit_after>/*
 * Copyright (C) 2012-2017  Online-Go.com
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as
 * published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

import * as React from "react";
import * as commonmark from "commonmark";

interface MarkdownProps {
    source: string;
}

let parser = new commonmark.Parser();
let renderer = new commonmark.HtmlRenderer();

export class Markdown extends React.PureComponent<MarkdownProps, {html}> {
    constructor(props) {
        super(props);
        this.state = {
            html: this.props.source ? renderer.render(parser.parse(this.massage(this.props.source))) : ""
        };
    }

    massage(source: string): string {
        source = source.replace(/^(#+)([a-zA-Z0-9])/g, "$1 $2"); // headers used to behave like this
        source = source.replace(/<script/ig, "(script"); // hasnt' been exploitable yet with how react works i don't think, but they leave most html intact for some stupid reason, this string shouldn't exist anyways
        source = source.replace(/^(https?:\/\/[^\s]+)/g, "[$1]($1)");
        source = source.replace(/[^[(](https?:\/\/[^\s\]\)]+)/g, "[$1]($1)");
        return source;
    }

    componentWillReceiveProps(next_props) {{{
        if (next_props.source !== this.props.source) {
            this.setState({
                html: next_props.source ? renderer.render(parser.parse(this.massage(next_props.source))) : ""
            });
        }
    }}}

    render() {
        return (
{'fraction_non_alphanumeric': 0.11879211380084852, 'fraction_numerical': 0.007486897928624906, 'mean_word_length': 3.0362537764350455, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4024549', 'n_tokens_mistral': 1135, 'n_tokens_neox': 1097, 'n_words': 402}