Skip to content

Commit

Permalink
Test folding changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Rarisma committed Dec 5, 2024
1 parent a1d9f76 commit d9f9cd3
Show file tree
Hide file tree
Showing 112 changed files with 121 additions and 20 deletions.
72 changes: 52 additions & 20 deletions MarkdownSplitter/Splitter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,6 @@

namespace MarkdownSplitter
{
/// <summary>
/// Generate the StoryBuilder User Manual website by processing
/// the output of a Scrivener Compile to MultiMarkdown.
/// The output of the Compile command is written to compilerFolder.
/// </summary>
public class Splitter
{
public string MarkdownFolder { get; set; }
Expand Down Expand Up @@ -140,7 +135,10 @@ private void RecurseMarkdownBlocks(Block block)

private void WriteMarkdownBlock(Block block)
{
string filepath = Path.Combine(docsFolder, block.Filename);
string outputDir = GetOutputDirectoryForBlock(block);
Directory.CreateDirectory(outputDir);

string filepath = Path.Combine(outputDir, block.Filename);
using StreamWriter file = new(filepath);
file.WriteLine("---");
file.WriteLine($"title: {block.Title}");
Expand All @@ -156,6 +154,9 @@ private void WriteMarkdownBlock(Block block)

private void WriteChildFile(Block block, Block parent)
{
string outputDir = GetOutputDirectoryForBlock(block);
Directory.CreateDirectory(outputDir);

StringBuilder sb = new();
sb.AppendLine("---");
sb.AppendLine($"title: {block.Title}");
Expand All @@ -171,16 +172,16 @@ private void WriteChildFile(Block block, Block parent)

foreach (var child in block.Children)
{
// Convert .md links to .html
string htmlLink = Path.ChangeExtension(child.Filename, ".html");
sb.AppendLine($"[{child.Title}]({htmlLink}) <br/><br/>");
}

File.WriteAllText(Path.Combine(docsFolder, block.Filename), sb.ToString());
File.WriteAllText(Path.Combine(outputDir, block.Filename), sb.ToString());

foreach (var child in block.Children)
WriteChildFile(child, block);
}

private string CleanupMarkdown(string line)
{
if (line.Contains("[Front Page (Image)](Front_Page_(Image).md)"))
Expand All @@ -189,8 +190,6 @@ private string CleanupMarkdown(string line)
if (line == " <br/>")
return "";

// Handle reference-style images: ![][refName]
// Convert them to ![](/media/refName.png)
if (line.Contains("![]["))
{
int startIndex = line.IndexOf("![][") + 4;
Expand All @@ -203,8 +202,6 @@ private string CleanupMarkdown(string line)
}
}

// Handle inline images: ![AltText](imageName)
// Add .png and prepend /media
if (line.IndexOf("![") > -1 && line.Contains("]("))
{
string[] tokens = line.Split(new[] { '(', ')' }, StringSplitOptions.RemoveEmptyEntries);
Expand All @@ -216,30 +213,22 @@ private string CleanupMarkdown(string line)
}
}

// Convert .md links to .html
if (line.Contains(".md"))
line = line.Replace(".md", ".html");

return line;
}

// This helper function ensures the image name is "cleaned" before we add "/media/" and ".png"
private string NormalizeImageName(string imageName)
{
// Remove any leading/trailing spaces
imageName = imageName.Trim();

// Remove any existing /media/ segment
imageName = imageName.Replace("/media/", "");

// Remove any trailing .png (or .PNG) extension if present
if (imageName.EndsWith(".png", StringComparison.OrdinalIgnoreCase))
imageName = imageName.Substring(0, imageName.Length - 4);

return imageName;
}


private void ChainBlocks(Block current, int index)
{
previousBlock!.Next = current;
Expand All @@ -254,5 +243,48 @@ private void ChainBlocks(Block current, int index)
previousBlock.Text.Add(sb.ToString());
previousBlock = current;
}

private string GetOutputDirectoryForBlock(Block block)
{
if (block.Parent == null || block.Parent == nestingLevel[0])
{
// If this is root or direct child of root, top-level directory is docs
if (block == nestingLevel[0])
{
// root block (index.md) stays in docs
return docsFolder;
}
else
{
// This is a top-level child block: create a directory based on its title
string safeTitle = SanitizeFolderName(block.Title);
return Path.Combine(docsFolder, safeTitle);
}
}
else
{
// For deeper levels, use top-level parent's title
Block topLevelParent = GetTopLevelParent(block);
string safeTitle = SanitizeFolderName(topLevelParent.Title);
return Path.Combine(docsFolder, safeTitle);
}
}

private Block GetTopLevelParent(Block block)
{
Block current = block;
while (current.Parent != null && current.Parent != nestingLevel[0])
{
current = current.Parent;
}
return current;
}

private string SanitizeFolderName(string name)
{
foreach (char c in Path.GetInvalidFileNameChars())
name = name.Replace(c, '_');
return name;
}
}
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
16 changes: 16 additions & 0 deletions docs/Quick Start/Preferences.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---
title: Preferences
layout: default
nav_enabled: true
nav_order: 20
parent: Menu Bar
---

Preferences Menu

The Preferences dialog is launched when you click on the Preferences button on the Menu Bar:

![](media/Prefences-CommandBar-Button.png)


More information can be found here:
File renamed without changes.
File renamed without changes.
File renamed without changes.
20 changes: 20 additions & 0 deletions docs/Quick Start/Reports.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
title: Reports
layout: default
nav_enabled: true
nav_order: 19
parent: Menu Bar
---

Reports

Clicking on the Reports button on the Menu Bar displays a fly-out menu with two reporting options:

![](media/Print-Reports-Button-and-Menu.png)


More information can be found here:

• Print Reports
• Scrivener Reports

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
33 changes: 33 additions & 0 deletions docs/Quick Start/Story_Elements.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
---
title: Story Elements
layout: default
nav_enabled: true
nav_order: 25
parent: Navigating in StoryCAD
---

Story Elements

Your outline is a tree of Story Elements which are displayed in the Navigation Pane. Clicking (or touching) a Story Element node on the Navigation Pane will display that Story Element’s content in the Content Pane.

Here, clicking on the first or root node in the tree displays the Story Overview Form.

On some screen sizes and orientations the Navigation and Content panes may be stacked with the Navigation pane above the Content pane. In those cases the Show/Hide Navigation button (the hamburger menu button) acts differently; it toggles from the Navigation Pane to the Content Pane and back.

![](media/Navigation-and-Content-Pane-1.png)

Every Story Element type is a different form. These are the story elements:

• Story Overview
• Problem
• Character
• Setting
• Scene
• Folder
• Section

Your outline has only one Story Overview; it’s created automatically when you open or create a new outline. The Story Overview is the root of the Navigation Pane tree, and all other Story Elements are below it.

Every form also has a full-page tab (labeled Notes) which holds your general notes and thoughts regarding the story element. We won’t talk about these again; just be aware that they’re there.


File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit d9f9cd3

Please sign in to comment.