briandk / transdown

A lightweight syntax for writing and presenting transcripts of qualitative research data.
3 stars 1 forks source link

Parsing reference links #9

Open briandk opened 9 years ago

briandk commented 9 years ago

So, suppose we're going to implement a two-pass solution for parsing the source text, and further suppose that solution goes as follows

Pass 1

@Wildoane suggests that an easy way to add a key iff it's unique is to first check whether the dictionary has it using hasOwnProperty, like so:

var addUniqueKeyToDictionary = function(dictionary, key, value) {
    if (!dictionary.hasOwnProperty(key)) {
        dictionary[key] = value;
    }
    return (dictionary)
}

addUniqueKeyToDictionary(myDictionary, "astronaut", "brian") 
// returns Object {astronaut: "brian"}

addUniqueKeyToDictionary(myDictionary, "astronaut", "harry") 
// returns Object {astronaut: "brian"}

addUniqueKeyToDictionary(myDictionary, "copilot", "harry") 
// returns Object {astronaut: "brian", copilot: "harry"}
briandk commented 9 years ago

Wil suggests that we could also think about a two-pass solution that expands reference-style links into inline links. So, suppose you have:

[some text][ref1]

[ref1]: https://github.com

On pass one, the reference links get parsed and added to a dictionary.

On pass two, all reference links are expanded out to inline links. So, the above text becomes:

[some text](https://github.com)

On pass 3 (if necessary) inline links are converted IMG elements (or whatever the media is)