get_code: Get code blocks from xml document

View source: R/get_code.R

get_codeR Documentation

Get code blocks from xml document

Description

Get code blocks from xml document

Usage

get_code(body, type = ".language-", attr = "@ktag")

Arguments

body

an xml document from a jekyll site

type

a full or partial string of a code block attribute from Jekyll without parenthesis.

attr

what attribute to query in search of code blocks. Default is @ktag, which will search for "{: \<type\>".

Details

This uses the XPath function fn:starts-with() to search for the code block and automatically includes the opening brace, so regular expressions are not allowed. This is used by the ⁠$code⁠, ⁠$output⁠, and ⁠$error⁠ elements of the Episode class.

Value

an xml nodeset object

Examples


e <- Episode$new(fs::path(lesson_fragment(), "_episodes", "17-scope.md"))

get_code(e$body)
get_code(e$body, ".output")
get_code(e$body, ".error")

zkamvar/up2code documentation built on Feb. 24, 2025, 7:32 a.m.