Skip to content

Instantly share code, notes, and snippets.

@Janooba
Created October 23, 2018 17:53
Show Gist options
  • Save Janooba/caf7e440479b8fa613b53c26bc89dc8b to your computer and use it in GitHub Desktop.
Save Janooba/caf7e440479b8fa613b53c26bc89dc8b to your computer and use it in GitHub Desktop.
for (int u = 0; u < blocks.Length; u++)
for (int v = 0; v < blocks[u].Span.Length; v++)
{
Block block = blocks[u];
Span span = blocks[u].Span[v];
// If there is a style, it has a list style, and it's list type isn't "None"
if (span.Text.Trim().Length > 0 &&
block.Style != null &&
block.Style.ListStyle != null &&
block.Style.ListStyle.ListType != "None")
{
if (block.Style.ListStyle.ListType == "Bullet")
{
stringBuilder.Append(block.Style.ListStyle.BulletChar + " ");
currentListNumber = 1; // Reset
}
else if (block.Style.ListStyle.ListType.Contains("ListNumbered"))
{
stringBuilder.Append(currentListNumber++ + ". ");
}
else
{
/* I don't know what other list types there are,
* but it's safe to say they aren't numbered.
*/
currentListNumber = 1;
}
}
else // No list, reset to 1
{
currentListNumber = 1;
}
// Add a space between spans that aren't line-breaks
if (u > 0 && u < blocks.Length - 1 && !span.Text.EndsWith("\n"))
stringBuilder.Append(" ");
stringBuilder.Append(span.Text);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment