diff --git a/docs/src/docs/c/index.tce b/docs/src/docs/c/index.tce
index edef99a..1777e8a 100644
--- a/docs/src/docs/c/index.tce
+++ b/docs/src/docs/c/index.tce
@@ -18,25 +18,96 @@ Section light
Markdown
Documentation is available for the following languages:
- - [C](/docs/c/) - 1% Complete
+ - [C](/docs/c/) - 10% Complete
- [JavaScript](/docs/javascript/) - 0% Complete
- [Python](/docs/python/) - 0% Complete
Heading 2 Getting Started
class mt-12 mb-6
-
Markdown
The core terrace parser is distributed as a single-header C library.
To use it, download [parser.h](https://git.thederf.com/thederf/Terrace/src/branch/main/packages/c/parser.h) and include in your project tree.
-
CodeBlock c
#include "parser.h"
- Markdown
-
Heading 2 Recipes
class mt-12
+ Heading 3 Parse a single line
+ Markdown
+ Parses a single line into `line_data`, the prints the information from `line_data`.
+ CodeBlock c
+ #include "parser.h"
+
+ int main(int argc, char *argv[]) {
+ char* line = "example line";
+ // Create the line_data struct
+ terrace_linedata_t line_data;
+ // Set the indent character to a space
+ line_data.indent = ' ';
+ // Populates line_data level, offsetHead, and offsetTail from line
+ terrace_parse_line(line, &line_data);
+
+ printf(
+ "level %u | indent %c | offsetHead %u | offsetTail %u\n",
+ line_data.level,
+ line_data.indent,
+ line_data.offsetHead,
+ line_data.offsetTail
+ );
+
+ return 0;
+ }
+
+ Heading 3 Parse all lines from stdin
+ Markdown
+ Reads lines from stdin one-by-one and prints each line's `line_data`.
+ CodeBlock c
+ #include "parser.h"
+ // Depends on several cstdlib functions
+ #include
+ #include
+ #include
+ #include
+
+ int main(int argc, char *argv[]) {
+ // Pointer to start of line
+ char *line = NULL;
+ // Initial size of the buffer to read into
+ // getline() will resize as needed
+ size_t bufsize = 128;
+ // How many characters have been read
+ ssize_t chars_read = 0;
+
+ // Create the line_data struct
+ terrace_linedata_t line_data;
+ // Set the indent character to a space
+ line_data.indent = ' ';
+
+ while (chars_read = getline(&line, &bufsize, stdin)) {
+ // If chars_read is -1, we've reached end of file.
+ if (chars_read == -1) break;
+ // getline returns lines with a trailing newline
+ // terrace_parse_line expects no trailing newline
+ // strip it off using strtok()
+ // (An odd solution, probably leaks memory)
+ char *terrace_line = strtok(line, "\n");
+ terrace_parse_line(terrace_line, &line_data);
+
+ printf(
+ "level %u | indent %c | offsetHead %u | offsetTail %u\n",
+ line_data.level,
+ line_data.indent,
+ line_data.offsetHead,
+ line_data.offsetTail
+ );
+ };
+
+ // Free the buffer allocated by getline().
+ free(line);
+ }
+
+
Heading 2 Core API
class mt-12
diff --git a/docs/src/parser/nodes/CodeBlock.js b/docs/src/parser/nodes/CodeBlock.js
index 2a4d22f..d5253e9 100644
--- a/docs/src/parser/nodes/CodeBlock.js
+++ b/docs/src/parser/nodes/CodeBlock.js
@@ -15,5 +15,7 @@ module.exports = async (doc, rootLevel) => {
else node.text = await contentAsText(doc, rootLevel, true)
}
+ node.text = node.text.trimEnd()
+
return node
}
diff --git a/docs/src/parser/page.js b/docs/src/parser/page.js
index df0f5af..3e69ec6 100644
--- a/docs/src/parser/page.js
+++ b/docs/src/parser/page.js
@@ -41,7 +41,6 @@ module.exports = async function(doc) {
})
pageData.headings = pageData.headings.filter(h => h.level === 2)
- console.dir(pageData.headings, { depth: null })
return pageData
}