Skip to content
Merged
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
appId: swmansion.enriched.markdown.example
tags:
- block
- list
- text
---
- launchApp

- runFlow:
file: '../../../../subflows/move_to_playground.yaml'

- runFlow:
file: '../../../subflows/set_enriched_text_value.yaml'
env:
VALUE: |
3. Add eggs and vanilla extract
4. Pour into a greased tin
5. Bake for 30 minutes

- runFlow:
file: '../../../subflows/capture_or_assert_screenshot.yaml'
env:
SCREENSHOT_NAME: 'ordered_list_start_display'
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 10 additions & 1 deletion packages/core/cpp/parser/MD4CParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class MD4CParser::Impl {
static const std::string ATTR_LANGUAGE;
static const std::string ATTR_IS_TASK;
static const std::string ATTR_TASK_CHECKED;
static const std::string ATTR_START;

void reset(size_t estimatedDepth) {
root = std::make_shared<MarkdownASTNode>(NodeType::Document);
Expand Down Expand Up @@ -114,7 +115,14 @@ class MD4CParser::Impl {
}

case MD_BLOCK_OL: {
impl->pushNode(std::make_shared<MarkdownASTNode>(NodeType::OrderedList));
auto node = std::make_shared<MarkdownASTNode>(NodeType::OrderedList);
if (detail) {
auto *ol = static_cast<MD_BLOCK_OL_DETAIL *>(detail);
if (ol->start != 1) {
node->setAttribute(ATTR_START, std::to_string(ol->start));
}
}
impl->pushNode(node);
break;
}

Expand Down Expand Up @@ -621,5 +629,6 @@ const std::string MD4CParser::Impl::ATTR_FENCE_CHAR = "fenceChar";
const std::string MD4CParser::Impl::ATTR_LANGUAGE = "language";
const std::string MD4CParser::Impl::ATTR_IS_TASK = "isTask";
const std::string MD4CParser::Impl::ATTR_TASK_CHECKED = "taskChecked";
const std::string MD4CParser::Impl::ATTR_START = "start";

} // namespace Markdown
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,10 @@ class BlockStyleContext {
listItemNumber++
}

fun resetListItemNumber() {
listItemNumber = 0
fun resetListItemNumber(startNumber: Int = 1) {
// ListItemRenderer pre-increments, so the counter starts one below the
// first rendered number.
listItemNumber = startNumber - 1
}

fun pushOrderedListItemNumber() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class ListContextManager(
fun enterList(
listType: BlockStyleContext.ListType,
style: ListStyle,
startNumber: Int = 1,
): ListEntryState {
val previousDepth = context.listDepth
val isNested = previousDepth > 0
Expand All @@ -58,7 +59,7 @@ class ListContextManager(
context.setUnorderedListStyle(style)
}
}
context.resetListItemNumber()
context.resetListItemNumber(startNumber)

return ListEntryState(
previousDepth = previousDepth,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,15 @@ class ListRenderer(
val listStyle = config.style.listStyle
val listType = if (isOrdered) BlockStyleContext.ListType.ORDERED else BlockStyleContext.ListType.UNORDERED

val startNumber =
if (isOrdered) {
node.getAttribute("start")?.toIntOrNull()?.coerceAtLeast(0) ?: 1
} else {
1
}

val contextManager = ListContextManager(factory.blockStyleContext)
val entryState = contextManager.enterList(listType, listStyle)
val entryState = contextManager.enterList(listType, listStyle, startNumber)

// For top-level lists, insert marginTop spacer before rendering content
if (entryState.previousDepth == 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,14 @@ - (void)renderNodeContent:(MarkdownASTNode *)node

context.listDepth = prevDepth + 1;
context.listType = _isOrdered ? ListTypeOrdered : ListTypeUnordered;
context.listItemNumber = 0; // Reset counter for this specific list level
NSInteger startNumber = 1;
NSString *startAttr = node.attributes[@"start"];
if (_isOrdered && startAttr != nil) {
startNumber = MAX((NSInteger)0, (NSInteger)startAttr.integerValue);
}
// ListItemRenderer pre-increments, so the counter starts one below the
// first rendered number.
context.listItemNumber = startNumber - 1;

[context setBlockStyle:_isOrdered ? BlockTypeOrderedList : BlockTypeUnorderedList
font:_config.listStyleFont
Expand Down
Loading