Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/backend/models/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
type BlockType string

const (
CodeBlock BlockType = "code"
TextBlock BlockType = "text"
TaskBlock BlockType = "task"
HeadingBlock BlockType = "header"
Expand Down
2 changes: 2 additions & 0 deletions src/frontend/lib/utils/attributed_text_utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class AttributedTextUtils {

// Use the same attribution types that SuperEditor uses in defaultStyleBuilder
final attributions = [
const NamedAttribution('code'),
const NamedAttribution('bold'),
const NamedAttribution('italics'),
const NamedAttribution('underline'),
Expand Down Expand Up @@ -157,6 +158,7 @@ class AttributedTextUtils {
if (start >= 0 && end > start && end <= text.length) {
// Apply attributions based on the type
switch (type) {
case 'code':
case 'bold':
case 'italics':
case 'underline':
Expand Down
32 changes: 29 additions & 3 deletions src/frontend/lib/utils/document_builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -626,6 +626,8 @@ class DocumentBuilder {
final levelStr = blockTypeStr.substring(6);
final level = int.tryParse(levelStr) ?? 1;
metadata['level'] = level;
} else if (blockType == 'code') {
metadata['code-block'] = node.metadata['code-block'] ?? 'plain';
}
} else if (node is TaskNode) {
content['text'] = node.text.toPlainText();
Expand Down Expand Up @@ -685,6 +687,8 @@ class DocumentBuilder {
blockType = 'header';
final levelStr = blockType.substring(6);
metadata['level'] = DataConverter.parseIntSafely(levelStr);
} else if (blockType == 'code') {
metadata['code-block'] = node.metadata['code-block'] ?? 'plain';
}
} else if (node is TaskNode) {
content['text'] = node.text.toPlainText();
Expand All @@ -699,11 +703,11 @@ class DocumentBuilder {

// Extract spans for list items
final spans =
_attributedTextUtils.extractSpansFromAttributedText(node.text);
_attributedTextUtils.extractSpansFromAttributedText(node.text);
metadata['spans'] = spans;

metadata['listType'] =
node.type == ListItemType.ordered ? 'ordered' : 'unordered';
node.type == ListItemType.ordered ? 'ordered' : 'unordered';
}

return {'content': content, 'metadata': metadata};
Expand Down Expand Up @@ -767,7 +771,29 @@ class DocumentBuilder {
return [
HorizontalRuleNode(
id: Editor.createNodeId(),
// metadata: metadata
),
];

case 'code':
final language = metadata != null
? metadata['code-block']?.toString() ?? 'plain'
: 'plain';
return [
ParagraphNode(
id: Editor.createNodeId(),
text: _attributedTextUtils
.createAttributedTextFromContent(text, {'metadata': metadata}),
metadata: {
'blockType': const NamedAttribution("code"),
'code-block': language,
'spans': [
{
'start': 1,
'end': text.length,
'type': 'code',
},
],
},
),
];

Expand Down