-
Notifications
You must be signed in to change notification settings - Fork 0
Research: Text formatting in Treebark - line breaks, markdown engine integration, and implementation approaches #73
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
|
@copilot is newline the only entity that should be considered? |
No, newline is not the only entity. Different platforms use different line endings: Must handle (critical):
Should NOT convert:
Correct implementation: Added comprehensive research showing:
See updated deliverables:
This is critical for cross-platform compatibility. |
|
@copilot let me invert my question: is br the only tag that we ought to consider? |
…bility Co-authored-by: danmarshall <[email protected]>
For this PR, yes - focus on Future consideration (as separate features):
Out of scope:
See full analysis in Recommendation: Start simple with |
|
@copilot can you reframe some of this research with the consideration of using a markdown engine? For example if we accepted a markdown-it instance in the renderoptions. |
Co-authored-by: danmarshall <[email protected]>
Added comprehensive analysis in Key findings: Option 1: Simple approach (
Option 2: Markdown engine (accept markdown-it instance)
Recommendation: Implement BOTH
Complementary to markdown-it-treebark: Different directions (Markdown IN Treebark vs Treebark IN Markdown), both valid. See full analysis with use case comparisons, API design, and security considerations. |
|
@copilot can you give examples of how markdown-it would be passed as an option, for these 3 :
|
…ee contexts Co-authored-by: danmarshall <[email protected]>
Added comprehensive examples in Node String: import { renderToString } from 'treebark';
import MarkdownIt from 'markdown-it';
const md = new MarkdownIt({ breaks: true, linkify: true });
renderToString(input, { markdown: md });Node DOM: import { renderToDOM } from 'treebark';
const md = new MarkdownIt({ breaks: true });
renderToDOM(input, container, { markdown: md });markdown-it plugin: import treebarkPlugin from 'markdown-it-treebark';
const textMd = new MarkdownIt({ breaks: true });
const md = new MarkdownIt();
md.use(treebarkPlugin, { markdown: textMd });Document includes complete working examples with imports, advanced configurations, security setup, use case decision tree, and testing examples. |
Research whether automatically converting line endings to
<br>tags is feasible, secure, desirable, and aligns with Treebark's design philosophy. Extended to analyze alternative approach using markdown engine integration with concrete code examples.Findings
Feasibility: ✅ Straightforward implementation - Updated to handle all line ending types:
Line Ending Types: Research expanded beyond just newline (
\n) to include:\n→<br>\r\n→ single<br>(critical: not double)\r→<br>Other HTML Tags: Research expanded to consider tags beyond
<br>:<br>only (simple, safe, solves immediate problem)<a>(auto-linking),<p>(smart paragraphs) as separate features*emphasis*,- lists) - conflicts with markdown-it-treebarkSecurity: ✅ Safe if escape-before-convert order enforced:
Design Alignment: Treebark follows React/HTML philosophy (explicit structure, no magic). Systems comparison:
Use Cases:
Recommendations
Approach 1: Simple Line Break Conversion (Original)
Implement as opt-in feature (disabled by default):
Best for: Simple cases (addresses, poems), no dependencies, covers 80% of use cases
Approach 2: Markdown Engine Integration (NEW)
Accept markdown-it instance for rich content formatting:
Best for: Rich user-generated content, auto-linking, full markdown features
Benefits:
Trade-offs:
Hybrid Recommendation (Preferred)
Implement BOTH approaches to serve different needs:
convertNewlinesToBrfor basic cases (no forced dependency)markdowntake precedence if both providedPreserves explicit-structure philosophy while enabling both simple and complex content-focused use cases.
Deliverables
Research documentation now in repository at
docs/research/:<br>(16.7 KB)Additional supporting research (referenced in README):
Total: 13 documents, ~142 KB of comprehensive research
Effort:
Risk: Low | Priority: Low-medium
Critical Findings
/\r?\n|\r/g(not just/\n/g) - simple pattern breaks on Windows<br>for simple approach; markdown engine provides all tagsmarkdownoption works across all three contexts (renderToString, renderToDOM, treebarkPlugin)Original prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.