This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export const peer_id = ""; // identifies this browser in the network | |
// Try_send and messages is how you would send sdp/ice candidates to signal your RTCPeerConnections. | |
export function try_send(peer_id, message) {} // Route a message through the network toward the peer. Unreliable since the peer could be offline or peers could fail in between. | |
const messages = new EventTarget(); // Receive messages from other peers. | |
// Would be used to join chatrooms: | |
export async function subscribe(topic_id) { [/* List of peers that have also subscribed to that topic */] } | |
export async function unsubscribe(topic) {} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Parse an open tag | |
const success = pull(/^<([a-zA-Z][a-zA-Z0-9\-]*)/, tag => { | |
const new_tag = { tag, attributes: {}, children: [] }; | |
cursor.children.push(new_tag); | |
parse_attributes(new_tag); | |
if (!VOID_TAGS.includes(tag.toLowerCase())) { | |
parse_content(new_tag); | |
} | |
}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const VOID_TAGS = [ | |
// List from: https://riptutorial.com/html/example/4736/void-elements | |
'area', | |
'base', | |
'br', | |
'hr', | |
'img', | |
'input', | |
'link', | |
'meta', |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Parse a comment node: | |
|| pull(/^<!--((?:[^-]|-(?!->))*)-->/, comment => { | |
cursor.children.push({ | |
comment | |
}) | |
}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function parse_attributes(cursor) { | |
while(pull(/^\s+([a-zA-Z][a-zA-Z0-9\-]+)="([^"]*)"/, ( | |
name, | |
value | |
) => { | |
cursor.attributes[name] = value; | |
})) {} | |
if (!pull(/^\s*>/)) { | |
throw new Error("Malformed open tag"); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pull(/^<([a-zA-Z][a-zA-Z0-9\-]*)/, tag => { | |
const new_tag = { tag, attributes: {}, children: [] }; | |
cursor.children.push(new_tag); | |
parse_attributes(new_tag); | |
parse_content(new_tag); | |
}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[{ tag: 'p', children: [ | |
{ text: "\n\t" }, | |
{ tag: 'b', children: [ | |
{ text: "bold content" } | |
]}, | |
{ text: "\n" } | |
]}] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<p> | |
<b>bold content</b> | |
</p> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Parse an open tag | |
const success = pull(/^<([a-zA-Z][a-zA-Z0-9\-]*)>/, tag => { | |
const new_tag = { tag, attributes: {}, children: [] }; | |
cursor.children.push(new_tag); | |
parse_content(new_tag); | |
}) || | |
// Parse close tag | |
pull(/^<\/([a-zA-Z][a-zA-Z0-9\-]*)>/, tag => { | |
if (cursor.tag.toLowerCase() !== tag.toLowerCase()) { | |
throw new Error("Unmatched close tag"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function parse_content(cursor) { | |
let run = true; | |
while (run && input.length > 0) { | |
// Parse an open tag | |
const success = pull(/^<([a-zA-Z][a-zA-Z0-9\-]*)>/, tag => { | |
const new_tag = { tag, attributes: {}, children: [] }; | |
cursor.children.push(new_tag); | |
parse_content(new_tag); | |
}) || | |
// Parse close tag |
NewerOlder