Templates Test

Next Example for json:

HTML Context

  • users = {'Employees': [{'userId': 'rirani', 'jobTitleName': 'Developer', 'firstName': 'Romin', 'lastName': 'Irani', 'preferredFullName': 'Romin Irani', 'employeeCode': 'E1', 'region': 'CA', 'phoneNumber': '408-1234567', 'emailAddress': 'romin.k.irani@gmail.com', 'is_active': True}, {'userId': 'nirani', 'jobTitleName': 'Developer', 'firstName': 'Neil', 'lastName': 'Irani', 'preferredFullName': 'Neil Irani', 'employeeCode': 'E2', 'region': 'CA', 'phoneNumber': '408-1111111', 'emailAddress': 'neilrirani@gmail.com', 'is_active': True}, {'userId': 'thanks', 'jobTitleName': 'Program Directory', 'firstName': 'Tom', 'lastName': 'Hanks', 'preferredFullName': 'Tom Hanks', 'employeeCode': 'E3', 'region': 'CA', 'phoneNumber': '408-2222222', 'emailAddress': 'tomhanks@gmail.com', 'is_active': False}]}

Employees

  • {'userId': 'rirani', 'jobTitleName': 'Developer', 'firstName': 'Romin', 'lastName': 'Irani', 'preferredFullName': 'Romin Irani', 'employeeCode': 'E1', 'region': 'CA', 'phoneNumber': '408-1234567', 'emailAddress': 'romin.k.irani@gmail.com', 'is_active': True}

Employees

  • {'userId': 'nirani', 'jobTitleName': 'Developer', 'firstName': 'Neil', 'lastName': 'Irani', 'preferredFullName': 'Neil Irani', 'employeeCode': 'E2', 'region': 'CA', 'phoneNumber': '408-1111111', 'emailAddress': 'neilrirani@gmail.com', 'is_active': True}

Employees

  • {'userId': 'thanks', 'jobTitleName': 'Program Directory', 'firstName': 'Tom', 'lastName': 'Hanks', 'preferredFullName': 'Tom Hanks', 'employeeCode': 'E3', 'region': 'CA', 'phoneNumber': '408-2222222', 'emailAddress': 'tomhanks@gmail.com', 'is_active': False}

  • data = {'key1': 'value1', 'key2': ['list item 1', 'list item 2', 'list item 3'], 'nested-list': [['a', 'b', 'c'], ['A', 'B', 'C']], 'mapping-series': [{'cola': 'a', 'colb': 'b', 'colc': 'c'}, {'cola': 'A', 'colb': 'B', 'colc': 'C'}]}

  • list item 1

  • list item 2

  • list item 3

  • uix = {'HeaderMenu': [{'class': 'menu-active', 'element': 'li', 'has_child': True, 'innerChild': [{'alt': '', 'class': '', 'element': 'a', 'href': 'index.html', 'id': '', 'is_active': True, 'placeholder': '', 'text': '{%trans%}home{%endtrans%}', 'title': '', 'value': ''}]}, {'class': '', 'element': 'li', 'has_child': True, 'innerChild': [{'alt': '', 'element': 'a', 'href': 'about-us.html', 'id': '', 'is_active': True, 'placeholder': '', 'text': '{%trans%}about us{%endtrans%}', 'title': '', 'value': ''}]}, {'class': 'menu-has-children', 'element': 'li', 'has_child': True, 'innerChild': [{'alt': '', 'element': 'a', 'href': 'about-us.html', 'id': '', 'is_active': True, 'placeholder': '', 'text': '{%trans%}pages{%endtrans%}', 'title': '', 'value': ''}, {'alt': '', 'class': '', 'element': 'ul', 'has_child': True, 'href': '', 'id': '', 'innerChild': [{'class': '', 'element': 'li', 'has_child': True, 'innerChild': [{'alt': '', 'element': 'a', 'href': 'a.html', 'id': '', 'is_active': True, 'placeholder': '', 'text': '{%trans%}a{%endtrans%}', 'title': '', 'value': ''}]}, {'class': '', 'element': 'li', 'has_child': True, 'innerChild': [{'alt': '', 'element': 'a', 'href': 'b.html', 'id': '', 'is_active': True, 'placeholder': '', 'text': '{%trans%}b{%endtrans%}', 'title': '', 'value': ''}]}], 'is_active': True, 'placeholder': '', 'text': '', 'title': '', 'value': ''}]}]}

  • copybutton_prompt_text = ````

  • copybutton_prompt_is_regexp = False

  • copybutton_only_copy_prompt_lines = True

  • copybutton_remove_prompts = True

  • copybutton_copy_empty_lines = True

  • copybutton_line_continuation_character = ````

  • copybutton_here_doc_delimiter = ````

  • copybutton_image_svg = ````

  • copybutton_selector = div.highlight pre

  • copybutton_format_func = ``function escapeRegExp(string) {

    return string.replace(/[.*+?^${}()|[]\]/g, ‘\$&’); // $& means the whole matched string

}

/**
  • Removes excluded text from a Node.

  • @param {Node} target Node to filter.

  • @param {string} exclude CSS selector of nodes to exclude.

  • @returns {DOMString} Text from target with text removed.

*/

function filterText(target, exclude) {

const clone = target.cloneNode(true); // clone as to not modify the live DOM if (exclude) {

// remove excluded nodes clone.querySelectorAll(exclude).forEach(node => node.remove());

} return clone.innerText;

}

// Callback when a copy button is clicked. Will be passed the node that was clicked // should then grab the text and replace pieces of text that shouldn’t be used in output function formatCopyText(textContent, copybuttonPromptText, isRegexp = false, onlyCopyPromptLines = true, removePrompts = true, copyEmptyLines = true, lineContinuationChar = “”, hereDocDelim = “”) {

var regexp; var match;

// Do we check for line continuation characters and “HERE-documents”? var useLineCont = !!lineContinuationChar var useHereDoc = !!hereDocDelim

// create regexp to capture prompt and remaining line if (isRegexp) {

regexp = new RegExp(‘^(’ + copybuttonPromptText + ‘)(.*)’)

} else {

regexp = new RegExp(‘^(’ + escapeRegExp(copybuttonPromptText) + ‘)(.*)’)

}

const outputLines = []; var promptFound = false; var gotLineCont = false; var gotHereDoc = false; const lineGotPrompt = []; for (const line of textContent.split(’n’)) {

match = line.match(regexp) if (match || gotLineCont || gotHereDoc) {

promptFound = regexp.test(line) lineGotPrompt.push(promptFound) if (removePrompts && promptFound) {

outputLines.push(match[2])

} else {

outputLines.push(line)

} gotLineCont = line.endsWith(lineContinuationChar) & useLineCont if (line.includes(hereDocDelim) & useHereDoc)

gotHereDoc = !gotHereDoc

} else if (!onlyCopyPromptLines) {

outputLines.push(line)

} else if (copyEmptyLines && line.trim() === ‘’) {

outputLines.push(line)

}

}

// If no lines with the prompt were found then just use original lines if (lineGotPrompt.some(v => v === true)) {

textContent = outputLines.join(’n’);

}

// Remove a trailing newline to avoid auto-running when pasting if (textContent.endsWith(”n”)) {

textContent = textContent.slice(0, -1)

} return textContent

}

  • copybutton_exclude = .linenos

Individual Inline Item

value1

List of Inline Items

  • list item 1

  • list item 2

  • list item 3

HTML Inline Context

  • users = {'Employees': [{'userId': 'rirani', 'jobTitleName': 'Developer', 'firstName': 'Romin', 'lastName': 'Irani', 'preferredFullName': 'Romin Irani', 'employeeCode': 'E1', 'region': 'CA', 'phoneNumber': '408-1234567', 'emailAddress': 'romin.k.irani@gmail.com', 'is_active': True}, {'userId': 'nirani', 'jobTitleName': 'Developer', 'firstName': 'Neil', 'lastName': 'Irani', 'preferredFullName': 'Neil Irani', 'employeeCode': 'E2', 'region': 'CA', 'phoneNumber': '408-1111111', 'emailAddress': 'neilrirani@gmail.com', 'is_active': True}, {'userId': 'thanks', 'jobTitleName': 'Program Directory', 'firstName': 'Tom', 'lastName': 'Hanks', 'preferredFullName': 'Tom Hanks', 'employeeCode': 'E3', 'region': 'CA', 'phoneNumber': '408-2222222', 'emailAddress': 'tomhanks@gmail.com', 'is_active': False}]}

  • data = {'key1': 'value1', 'key2': ['list item 1', 'list item 2', 'list item 3'], 'nested-list': [['a', 'b', 'c'], ['A', 'B', 'C']], 'mapping-series': [{'cola': 'a', 'colb': 'b', 'colc': 'c'}, {'cola': 'A', 'colb': 'B', 'colc': 'C'}]}

  • uix = {'HeaderMenu': [{'class': 'menu-active', 'element': 'li', 'has_child': True, 'innerChild': [{'alt': '', 'class': '', 'element': 'a', 'href': 'index.html', 'id': '', 'is_active': True, 'placeholder': '', 'text': '{%trans%}home{%endtrans%}', 'title': '', 'value': ''}]}, {'class': '', 'element': 'li', 'has_child': True, 'innerChild': [{'alt': '', 'element': 'a', 'href': 'about-us.html', 'id': '', 'is_active': True, 'placeholder': '', 'text': '{%trans%}about us{%endtrans%}', 'title': '', 'value': ''}]}, {'class': 'menu-has-children', 'element': 'li', 'has_child': True, 'innerChild': [{'alt': '', 'element': 'a', 'href': 'about-us.html', 'id': '', 'is_active': True, 'placeholder': '', 'text': '{%trans%}pages{%endtrans%}', 'title': '', 'value': ''}, {'alt': '', 'class': '', 'element': 'ul', 'has_child': True, 'href': '', 'id': '', 'innerChild': [{'class': '', 'element': 'li', 'has_child': True, 'innerChild': [{'alt': '', 'element': 'a', 'href': 'a.html', 'id': '', 'is_active': True, 'placeholder': '', 'text': '{%trans%}a{%endtrans%}', 'title': '', 'value': ''}]}, {'class': '', 'element': 'li', 'has_child': True, 'innerChild': [{'alt': '', 'element': 'a', 'href': 'b.html', 'id': '', 'is_active': True, 'placeholder': '', 'text': '{%trans%}b{%endtrans%}', 'title': '', 'value': ''}]}], 'is_active': True, 'placeholder': '', 'text': '', 'title': '', 'value': ''}]}]}

  • copybutton_prompt_text = ````

  • copybutton_prompt_is_regexp = False

  • copybutton_only_copy_prompt_lines = True

  • copybutton_remove_prompts = True

  • copybutton_copy_empty_lines = True

  • copybutton_line_continuation_character = ````

  • copybutton_here_doc_delimiter = ````

  • copybutton_image_svg = ````

  • copybutton_selector = div.highlight pre

  • copybutton_format_func = ``function escapeRegExp(string) {

    return string.replace(/[.*+?^${}()|[]\]/g, ‘\$&’); // $& means the whole matched string

}

/**
  • Removes excluded text from a Node.

  • @param {Node} target Node to filter.

  • @param {string} exclude CSS selector of nodes to exclude.

  • @returns {DOMString} Text from target with text removed.

*/

function filterText(target, exclude) {

const clone = target.cloneNode(true); // clone as to not modify the live DOM if (exclude) {

// remove excluded nodes clone.querySelectorAll(exclude).forEach(node => node.remove());

} return clone.innerText;

}

// Callback when a copy button is clicked. Will be passed the node that was clicked // should then grab the text and replace pieces of text that shouldn’t be used in output function formatCopyText(textContent, copybuttonPromptText, isRegexp = false, onlyCopyPromptLines = true, removePrompts = true, copyEmptyLines = true, lineContinuationChar = “”, hereDocDelim = “”) {

var regexp; var match;

// Do we check for line continuation characters and “HERE-documents”? var useLineCont = !!lineContinuationChar var useHereDoc = !!hereDocDelim

// create regexp to capture prompt and remaining line if (isRegexp) {

regexp = new RegExp(‘^(’ + copybuttonPromptText + ‘)(.*)’)

} else {

regexp = new RegExp(‘^(’ + escapeRegExp(copybuttonPromptText) + ‘)(.*)’)

}

const outputLines = []; var promptFound = false; var gotLineCont = false; var gotHereDoc = false; const lineGotPrompt = []; for (const line of textContent.split(’n’)) {

match = line.match(regexp) if (match || gotLineCont || gotHereDoc) {

promptFound = regexp.test(line) lineGotPrompt.push(promptFound) if (removePrompts && promptFound) {

outputLines.push(match[2])

} else {

outputLines.push(line)

} gotLineCont = line.endsWith(lineContinuationChar) & useLineCont if (line.includes(hereDocDelim) & useHereDoc)

gotHereDoc = !gotHereDoc

} else if (!onlyCopyPromptLines) {

outputLines.push(line)

} else if (copyEmptyLines && line.trim() === ‘’) {

outputLines.push(line)

}

}

// If no lines with the prompt were found then just use original lines if (lineGotPrompt.some(v => v === true)) {

textContent = outputLines.join(’n’);

}

// Remove a trailing newline to avoid auto-running when pasting if (textContent.endsWith(”n”)) {

textContent = textContent.slice(0, -1)

} return textContent

}

  • copybutton_exclude = .linenos


Last update: Nov 20, 2024