Module

TransportDiagram

From Dogcraft Wiki

No edit summary
No edit summary
 
(44 intermediate revisions by 2 users not shown)
Line 1: Line 1:
-- Module for generating mini diagrams of transport networks
-- Copyright (c) 2022, William278, Dogcraft.net and contributors
--
-- Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"),
-- to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
-- and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
--
-- The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
--
-- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
-- WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
--
-- End license text.
 
-- A Module for generating mini diagrams of transport networks
local p = {}
local p = {}
local data
local data = ""
local title = "Transport Diagram"
local totalTracks = 1


-- Keys for parsing lines
-- Extract the first internal link from a string and return its target page
local lineKeys = {"track_type", "row_type", "l_text", "l_link", "image", "secondary_image", "r_text", "r_link"}
local function findLink(text)
-- row_type: single or double line
text = string.match(text, "%[%[.-%]%]")
-- l_text: left station text
if text == nil then
-- r_text: right station text
return ""  
-- l_link: left station link
end
-- r_link: right station link
text = string.gsub(text, "[%[%]]", "")
-- image: image to use for the line
text = mw.text.split(text, "|", true)[1]
-- secondary_image: image to use for the line if it is a double line
return text
end


local function generate()
-- Generate the HTML for a diagram row
-- Use mw.text.split to split the data into lines
local function generateRow(tracks, trackTypes, leftStation, rightStation)
     local lines = mw.text.split(data, "\n")
    -- Create the row HTML
    local lineHtml = "<div class='diagram-row'>"
   
    -- Get a station link if present
    local stationLink = findLink("" .. leftStation .. rightStation)
 
    -- Add the left station text
    lineHtml = lineHtml .. "<div class='station station-left'>" .. leftStation .. "</div>"
 
    -- Add container box, with fixed width based on tracks count
     local width = 30 * totalTracks
    lineHtml = lineHtml .. "<div class='track-container' style='width: " .. tostring(width) .. "px'>"


     -- Iterate through each line, calling parseLine on it and appending the string result of that to an output data
     -- Add the track images
    local output = "<div class='transport-diagram'>"
    for trackIndex = 1, totalTracks do
    for _, line in ipairs(lines) do
        if tracks[trackIndex] ~= nil then
        output = output .. parseLine(line)
            -- If station or interchange, set targetPage to stationLink
            local targetPage = ""
            local trackCodeStart = string.sub(tracks[trackIndex], 1, 3)
    targetPage = (trackCodeStart == "STN" or trackCodeStart == "ITC") and stationLink or ""
           
            -- Add the track
            lineHtml = lineHtml ..
                "<div class='track'>[[File:TIcon " ..
                trackTypes[trackIndex] .. " " .. tracks[trackIndex] .. ".png|link=" .. targetPage .. "]]</div>"
        else
            -- Add a blank track if there isn't a track for this index
            lineHtml = lineHtml .. "<div class='track'>[[File:TIcon Blank.png|link=]]</div>"
        end
     end
     end
     return output .. "</div>"
     lineHtml = lineHtml .. "</div>"
 
    -- Add the right station text
    lineHtml = lineHtml .. "<div class='station station-right'>" .. rightStation .. "</div></div>"
    return lineHtml
end
end


-- Parses a line and generates the HTML for it
local function parseLine(line)
local function parseLine(line)
     -- Prepare values for row generation
     -- Prepare values for row generation
     local trackType = "SRN"
     local tracks = {}
     local rowType = "single"
    local trackTypes = { "SRN", "SRB", "SRB", "SRB" }
     local leftText = ""
     local leftStation = ""
     local rightText = ""
     local rightStation = ""
     local image = ""
 
     local secondaryImage = ""
    -- Trim the line of whitespace
     line = mw.text.trim(line)
 
    -- Split the line into colon separated key-pairs by commas
     local pairs = mw.text.split(line, ",", true)
     for i = 1, #pairs do
        -- Get the value
        local value = pairs[i]


    -- Split the line into equals-sign separated key-pairs by commas
    local pairs = mw.text.split(line, ",")
    for _, pair in ipairs(pairs) do
         -- Split the key-pair into a key and a value
         -- Split the key-pair into a key and a value
         local key, value = mw.text.split(pair, "=", true)
         local keyValue = mw.text.split(value, ":", true)
          
         local key = mw.text.trim(keyValue[1])
         -- Iterate through each possible key in lineKeys and set the appropriate values
        local value = mw.text.trim(keyValue[2])
         for _, lineKey in ipairs(lineKeys) do
 
            if key == lineKey then
         -- Parse the key and set the appropraite value
                if (key == "track_type") then
         if (key == "diagram-title" or key == "title") then
                    trackType = value
            title = value
                elseif (key == "row_type") then
        elseif (key == "diagram-tracks" or key == "tracks") then
                    rowType = value
            totalTracks = tonumber(value)
                elseif (key == "l_text") then
        elseif (key == "station") then
                    leftText = value
            leftStation = value
                elseif (key == "r_text") then
        elseif (key == "station2" or key == "station-right") then
                    rightText = value
            rightStation = value
                elseif (key == "l_link") then
        else
                    leftLink = value
            -- Handle track and trackType definitions
                 elseif (key == "r_link") then
            if string.sub(key, 1, 5) == "track" then
                     rightLink = value
                -- Get the track number
                 elseif (key == "image") then
                 local trackNumber = string.sub(key, 6, 6)
                     image = value
                if trackNumber == "-" or trackNumber == "" or trackNumber == nil then
                 elseif (key == "secondary_image") then
                     trackNumber = "1"
                    secondaryImage = value
                end
 
                -- If the key ends with -type, then it's a track type key
                 if string.sub(key, -5) == "-type" then
                     trackTypes[tonumber(trackNumber)] = value
                 else
                    tracks[tonumber(trackNumber)] = value
                 end
                 end
             end
             end
Line 64: Line 119:
     end
     end


     -- Generate the row HTML
     -- If tracks is empty, then there's no data for this line
     return generateRow(trackType, rowType, leftText, rightText, leftLink, rightLink, image, secondaryImage)
    if next(tracks) == nil then
        return ""
    end
 
     return generateRow(tracks, trackTypes, leftStation, rightStation)
end
end


local function generateRow(trackType, rowType, leftText, rightText, leftLink, rightLink, image, secondaryImage)
-- Generates the html for provided diagram markup
     -- Create the row HTML
local function generate()
     lineHtml = "<div class='diagram-row'>"
     -- Trim data of whitespace
     data = mw.text.trim(data)


     -- Add the left station text
     -- Use mw.text.split to split the data into lines
    lineHtml = lineHtml .. "<div class='station station-left'>"
     local lines = mw.text.split(data, "\n")
     -- If left link is not a blank string, add a link
    if leftLink ~= "" then
        lineHtml = lineHtml .. "<a href='" .. leftLink .. "'>"
    end
    lineHtml = lineHtml .. "<span>" .. leftText .. "</span>"
    -- If left link is not a blank string, close the link
    if leftLink ~= "" then
        lineHtml = lineHtml .. "</a>"
    end
    lineHtml = lineHtml .. "</div>"
   
    -- Add the track images
    lineHtml = lineHtml .. "<div class='track-container'>"
    -- Add the first image
    lineHtml = lineHtml .. "<div class='track'><img src='https://dogcraft.net/wiki/Special:FilePath/TIcon_" .. trackType .. "_" .. image .. ".png?width=30'></div>"
    -- Add the second image if present
    if rowType == "double" then
        lineHtml = lineHtml .. "<div class='track'><img src='https://dogcraft.net/wiki/Special:FilePath/" .. trackType .. "_" .. secondaryImage .. ".png?width=30'></div>"
    end
    lineHtml = lineHtml .. "</div>"


     -- Add the right station text
     -- Iterate through each line, calling parseLine on it and appending the string result of that to an output data
    lineHtml = lineHtml .. "<div class='station station-right'>"
     local output = ""
    -- If right link is not a blank string, add a link
     for _, line in ipairs(lines) do
    if rightLink ~= "" then
         output = output .. parseLine(line)
        lineHtml = lineHtml .. "<a href='" .. rightLink .. "'>"
     end
    lineHtml = lineHtml .. "<span>" .. rightText .. "</span>"
     -- If right link is not a blank string, close the link
    if rightLink ~= "" then
         lineHtml = lineHtml .. "</a>"
     end
     end
 
     return "<div class='transport-diagram phonefullscreen'><div class='transport-diagram-title'>" ..
     lineHtml = lineHtml .. "</div></div>"
        title .. "</div>" .. output .. "</div>"
    return lineHtml
end
end


-- The main function called on #invoke via the template
function p.transportDiagram(frame)
function p.transportDiagram(frame)
local args = {}
    local args = {}
if frame == mw.getCurrentFrame() then
    if frame == mw.getCurrentFrame() then
args = frame:getParent().args
        args = frame:getParent().args
else
    else
args = frame
        args = frame
end
    end
   
 
     -- Iterate through each key pair in args
     -- Iterate through each key pair in args
    local test = ""
     for key, value in pairs(args) do
     for key, value in pairs(args) do
         -- Add to test
         -- Add to data
         test = test .. key .. "  ==> " .. value .. "\n"
         data = data .. value
     end
     end
    return test
 
   
     return generate()
     -- return generate()
end
end


return p
return p

Latest revision as of 22:13, 4 October 2022


{{TransportDiagram}} is a template that uses Module:TransportDiagram to produce diagrams of transport networks on the Dogcraft Server. The module accepts a simple line-by-line parameter-based markup to produce the diagrams.

This template is not for making geographically accurate maps, but rather handy navigational templates and should be used instead of cumbersome lists for navigating between popular station articles, although note this map is primarily designed for use with railway or railway-style transit infrastructure, so may not be appropriate in all settings. Different networks will require different icons.

Specification

A TransportDiagram can be used with the following specification. It is important to note that this template only accepts one parameter; a text block of special Dogcraft Wiki TransportDiagram markup.

Template opener

Open a TransportDiagram template with the template identifer: {{TransportDiagram|

TransportDiagram Markup

The markup accepted by a TransportDiagram is formatted as described below. Please note that while TransportDiagram markup is whitespace insignificant, line terminators (\n) are considered significant and should not be used.

Rows

Markup is parsed line-by-line to generate each row of tracks. To separate two lines, use a simple newline return (ENTER ⏎).

A TransportDiagram is structured with the following rows: 1. Header (0-1) 2. Track and station rows (0-999)

Empty rows will be skipped. For example, the following four lines will be parsed as three rows, with the third line being skipped:

property: value, property2: value, property3: value
property: value, property2: value, property3: value

property: value, property2: value, property3: value

Property format

Each line, or row, of TransportDiagram markup is comprised by a series of comma-separated (,) parameters, which themselves are key-value pairs delimited by colons (:).

Example row: property: value, property2: foo bar, property3: foo la la

Property keys and values can contain any character, except exclamation points, commas, colons and exclamation points (used for delimitation).

Header row

The first row should, by convention, specify metadata about the template display, including the title and number of parallel tracks.

Header properties:

  • diagram-title or title - string - The title of the diagram (e.g. "East Station"). Can contain wiki markup, including [[Links]]
  • diagram-tracks or tracks - integer - The number of tracks to display, inclusively between 1 and 4; 1 >= n <= 4

Track and station rows

Every row after the first should contain track and station data.

Note that TransportDiagrams can have between one and four track columns inclusively. This means that each row can display up to four track icons. If you are using more than one column, you must remember to specify the diagram-tracks property in the header row, otherwise columns beyond the first one will not appear.

Track and station properties

  • track[n] - string, where [n] in the key optionally specifies the track column (1-4, from left to right), though is not required and defaults to 1. - Determines the visual appearance of the track on that column; the icon that is to be used. See below for a list of possible icons that can be used for this property.
  • track[n]-type - string, where [n] in the key optionally specifies the track column (1-4, from left to right), though is not required and defaults to 1. - Controls the color of the track to be used, conforming to the branding color of the associated network (e.g. SRN for Survival Railway Network). This is partly used in selecting the icon that will appear for the track. See below for a list of the available track types. If this parameter is not specified, the default for the first track is SRN, followed by SRB for columns 2, 3 and 4.
  • station - string - The wikitext to display to the left of the first track column on this row, indicating a station or annotation about the adjacent icons. (e.g. Ouranos Station)
  • station2 or station-right - string - The wikitext to display to the right of the last track column on this row, indicating a station or annotation about the adjacent icons.

If no valid station data properties are present on a row, it will be ignored. At a bare minimum, one valid track item is required to generate a row.

Track icons

There are 25 track icons in total, the color of which is determined by the track[n]-type property and the shape of which is determined by the track[n] property.

Track types (track[n]-type): The following track types are available for each network project (case sensitive).

Track images (track[n]) Track icon image file names are formatted as follows:

  • 3-letter piece code, capitalized
  • (underscore or blank space)
  • 0-2 letter track directions, capitalized. If the piece has track exiting the top, this is N. If the piece has track exiting the bottom, this is S. If the piece has track exiting the top and bottom, this is NS.
  • (underscore or blank space, if track augmentations need to be specified)
  • 0-3 letter track augmentations. The only current augmentation is a connection augmentation, represented by C; if a track connects to an adjacent piece to the right, this is EC (East Connection). If a track connects to an adjacent piece to the left, this is WC (West Connection). If this track is a middle-piece that connects to pieces on both the left and right, this is EWC (East, West Connection).
Table of available track icon codes (with track-type: SRN)
Icon display Piece code Piece type Track directions Track augmentations
TIcon SRN TRK NS.png
TRK NS Track North, South -
TIcon SRN STN S.png
STN S Station South -
TIcon SRN STN N.png
STN N Station North -
TIcon SRN STN NS.png
STN NS Station North, South -
TIcon SRN ITC S.png
ITC S Interchange South -
TIcon SRN ITC N.png
ITC N Interchange North -
TIcon SRN ITC NS.png
ITC NS Interchange North, South -
TIcon SRN ITC S EC.png
ITC S EC Interchange South East Connection
TIcon SRN ITC S WC.png
ITC S WC Interchange South West Connection
TIcon SRN ITC S EWC.png
ITC S EWC Interchange South East, West Connection
TIcon SRN ITC N EC.png
ITC N EC Interchange North East Connection
TIcon SRN ITC N WC.png
ITC N WC Interchange North West Connection
TIcon SRN ITC N EWC.png
ITC N EWC Interchange North East, West Connection
TIcon SRN ITC NS EC.png
ITC NS EC Interchange North, South East Connection
TIcon SRN ITC NS WC.png
ITC NS WC Interchange North, South West Connection
TIcon SRN ITC NS EWC.png
ITC NS EWC Interchange North, South East, West Connection
TIcon SRN ITC EWC.png
ITC EWC Interchange - East, West Connection
TIcon SRN JNC WC.png
JNC WC Junction (not required) West Connection
TIcon SRN JNC EC.png
JNC EC Junction (not required) East Connection
TIcon SRN CRN S EC.png
CRN N EC Corner North East Connection
TIcon SRN CRN N EC.png
CRN S EC Corner South East Connection
TIcon SRN CRN N WC.png
CRN N WC Corner North West Connection
TIcon SRN CRN S WC.png
CRN S WC Corner South West Connection
TIcon SRN CNT S.png
CNT S Continuity South -
TIcon SRN CNT N.png
CNT N Continuity North -

Content rules

Please note that the equals sign (=) and exclamation mark (!) must not be used within the template markup data. Duly also note that templates are resolved and substituted before being passed into the backend lua module that powers this template. It is possible to pass escaped wikitext markup, such as special words, however, to work around this.

Error handling

Using invalid properties will silently fail as they will not be read. Using invalid characters will return a lua error in place of the template.

Template closer

Don't forget to close a TransportDiagram with two curly braces: }}

Examples

Below are some valid examples of TemplateDiagrams in action.

Ouranos Metro

The Ouranos Metro map was used to help plan this specification. It's a simple short network but demonstrates the versatility of the diagrams in representing different modes of travel.

Ouranos Metro
Castle Station
TIcon ORM STN S.png
TIcon SRB CNT N.png
Central Station
TIcon ORM ITC NS EC.png
TIcon SRB ITC N WC.png
East Gate Station
TIcon ORM STN NS.png
TIcon Blank.png
Raceway Station
TIcon ORM ITC N.png
TIcon Blank.png


{{TransportDiagram|
diagram-title: Ouranos Metro, diagram-tracks: 2
track-type: ORM, track: STN S, station: Castle Station, track2: CNT N, track2-type: SRB, station2: ''to [[Cool Cove Station|Cool Cove]] ([[Survival Railway Network (Survival 3)|SRN]])''
track-type: ORM, track: ITC NS EC, station: Central Station, track2: ITC N WC, track2-type: SRB
track-type: ORM, track: STN NS, station: [[The Chase|Theatre Station]]
track-type: ORM, track: STN NS, station: East Gate Station
track-type: ORM, track: ITC N, station: Raceway Station
}}

West Line (Survival 3)

The West Line on the Survival 3 SRN is one of the most complex lines to have been built and utilities three of the four available columns to display it, in full (with exception to the Avalanche line). Below is the markup that makes it work.

{{TransportDiagram|
diagram-title: West Line (Survival 3), diagram-tracks: 3
track: ITC S, station: [[Grand Central Station (Survival 3)|Grand Central]]
track: ITC NS, station: [[Mall Station (Survival 3)|Mall Station]]
track: ITC NS, station: [[Balaton Station]]
track: TRK NS, track3: ITC S, station2: ''Wolfhaven Station''
track: TRK NS, track3: ITC NS, station2: ''Snowfields Station''
track: ITC NS EC, station: [[Bastion Glace Station|Bastion Glace]], track2: ITC EWC, track3: ITC NS WC
track: TRK NS, track3: ITC NS, station2: ''Everec Station''
track: TRK NS, track2: CNT N, track3: TRK NS, station: ''to the [[Avalanche Branch Line|Avalanche Line]]''
track: TRK NS, track2: TRK NS, track3: ITC NS, station2: ''Wilder Station''
track: ITC NS EC, station: [[Relleka Station]], track2: ITC NS WC, track3: TRK NS
track: TRK NS, track2: ITC NS, track3: TRK NS, station: ''Jello Station''
track: TRK NS, track2: ITC NS EC, track3: ITC NS WC, station2: ''Meander Station''
track: TRK NS, track2: TRK NS, track3: ITC NS, station2: ''Cantina Station''
track: TRK NS, track2: ITC NS, track3: TRK NS, station: ''Cloud Station''
track: TRK NS, track2: TRK NS, track3: ITC NS, station2: ''[[Build Battles]]''
track: TRK NS, track2: ITC NS, track3: TRK NS, station: ''Edgecliff Station''
track: TRK NS, track2: TRK NS, track3: ITC N, station2: ''Aeghu's Station''
track: TRK NS, track2: ITC NS, station: ''[[Cyberdog Safaris|Safari Station]]''
track: TRK NS, track2: ITC N, station: ''[[Ratanga Junction]]''
track: ITC N, station: [[The Rock Station|The Rock]]
}}



-- Copyright (c) 2022, William278, Dogcraft.net and contributors
-- 
-- Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"),
-- to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
-- and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
-- 
-- The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
-- 
-- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
-- WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-- 
-- End license text.

-- A Module for generating mini diagrams of transport networks
local p = {}
local data = ""
local title = "Transport Diagram"
local totalTracks = 1

-- Extract the first internal link from a string and return its target page
local function findLink(text)
	text = string.match(text, "%[%[.-%]%]")
	if text == nil then 
		return "" 
	end
	text = string.gsub(text, "[%[%]]", "")
	text = mw.text.split(text, "|", true)[1]
	return text	
end

-- Generate the HTML for a diagram row
local function generateRow(tracks, trackTypes, leftStation, rightStation)
    -- Create the row HTML
    local lineHtml = "<div class='diagram-row'>"
    
    -- Get a station link if present
    local stationLink = findLink("" .. leftStation .. rightStation)

    -- Add the left station text
    lineHtml = lineHtml .. "<div class='station station-left'>" .. leftStation .. "</div>"

    -- Add container box, with fixed width based on tracks count
    local width = 30 * totalTracks
    lineHtml = lineHtml .. "<div class='track-container' style='width: " .. tostring(width) .. "px'>"

    -- Add the track images
    for trackIndex = 1, totalTracks do
        if tracks[trackIndex] ~= nil then
            -- If station or interchange, set targetPage to stationLink
            local targetPage = ""
            local trackCodeStart = string.sub(tracks[trackIndex], 1, 3)
    		targetPage = (trackCodeStart == "STN" or trackCodeStart == "ITC") and stationLink or ""
            
            -- Add the track
            lineHtml = lineHtml ..
                "<div class='track'>[[File:TIcon " ..
                trackTypes[trackIndex] .. " " .. tracks[trackIndex] .. ".png|link=" .. targetPage .. "]]</div>"
        else
            -- Add a blank track if there isn't a track for this index
            lineHtml = lineHtml .. "<div class='track'>[[File:TIcon Blank.png|link=]]</div>"
        end
    end
    lineHtml = lineHtml .. "</div>"

    -- Add the right station text
    lineHtml = lineHtml .. "<div class='station station-right'>" .. rightStation .. "</div></div>"
    return lineHtml
end

-- Parses a line and generates the HTML for it
local function parseLine(line)
    -- Prepare values for row generation
    local tracks = {}
    local trackTypes = { "SRN", "SRB", "SRB", "SRB" }
    local leftStation = ""
    local rightStation = ""

    -- Trim the line of whitespace
    line = mw.text.trim(line)

    -- Split the line into colon separated key-pairs by commas
    local pairs = mw.text.split(line, ",", true)
    for i = 1, #pairs do
        -- Get the value
        local value = pairs[i]

        -- Split the key-pair into a key and a value
        local keyValue = mw.text.split(value, ":", true)
        local key = mw.text.trim(keyValue[1])
        local value = mw.text.trim(keyValue[2])

        -- Parse the key and set the appropraite value
        if (key == "diagram-title" or key == "title") then
            title = value
        elseif (key == "diagram-tracks" or key == "tracks") then
            totalTracks = tonumber(value)
        elseif (key == "station") then
            leftStation = value
        elseif (key == "station2" or key == "station-right") then
            rightStation = value
        else
            -- Handle track and trackType definitions
            if string.sub(key, 1, 5) == "track" then
                -- Get the track number
                local trackNumber = string.sub(key, 6, 6)
                if trackNumber == "-" or trackNumber == "" or trackNumber == nil then
                    trackNumber = "1"
                end

                -- If the key ends with -type, then it's a track type key
                if string.sub(key, -5) == "-type" then
                    trackTypes[tonumber(trackNumber)] = value
                else
                    tracks[tonumber(trackNumber)] = value
                end
            end
        end
    end

    -- If tracks is empty, then there's no data for this line
    if next(tracks) == nil then
        return ""
    end

    return generateRow(tracks, trackTypes, leftStation, rightStation)
end

-- Generates the html for provided diagram markup
local function generate()
    -- Trim data of whitespace
    data = mw.text.trim(data)

    -- Use mw.text.split to split the data into lines
    local lines = mw.text.split(data, "\n")

    -- Iterate through each line, calling parseLine on it and appending the string result of that to an output data
    local output = ""
    for _, line in ipairs(lines) do
        output = output .. parseLine(line)
    end
    return "<div class='transport-diagram phonefullscreen'><div class='transport-diagram-title'>" ..
        title .. "</div>" .. output .. "</div>"
end

-- The main function called on #invoke via the template
function p.transportDiagram(frame)
    local args = {}
    if frame == mw.getCurrentFrame() then
        args = frame:getParent().args
    else
        args = frame
    end

    -- Iterate through each key pair in args
    for key, value in pairs(args) do
        -- Add to data
        data = data .. value
    end

    return generate()
end

return p
Background Dragon Slayer - Retriever by Ironboundred