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
43 changes: 34 additions & 9 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ name: CI

on:
push:
branches: [ main ]
branches:
- '**'
tags: ['v*']
pull_request:
branches: [ main ]
Expand All @@ -23,34 +24,58 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Setup .NET
uses: actions/setup-dotnet@v3
uses: actions/setup-dotnet@v4
with:
dotnet-version: '10.0.x'
include-prerelease: true

- name: Determine Version
id: versioning
shell: bash
run: |
# Base version for main branch builds
BASE_VERSION="1.0.0"

if [[ "${{ github.ref }}" == refs/tags/v* ]]; then
# Extract version from tag (e.g., v1.2.3 -> 1.2.3)
VERSION="${GITHUB_REF#refs/tags/v}"
elif [[ "${{ github.ref }}" == "refs/heads/main" ]]; then
# Create a pre-release version for main branch (e.g., 1.0.0-preview.42)
VERSION="${BASE_VERSION}-preview.${{ github.run_number }}"
else
# Default for PRs or other branches
VERSION="${BASE_VERSION}-ci.${{ github.run_number }}"
fi

echo "VERSION=$VERSION" >> $GITHUB_OUTPUT
echo "Computed Version: $VERSION"

- name: Restore
run: dotnet restore

- name: Build
run: dotnet build --configuration Release --no-restore --nologo
run: dotnet build --configuration Release --no-restore --nologo -p:Version=${{ steps.versioning.outputs.VERSION }}

- name: Pack
run: |
dotnet pack MarkdownToPdf/MarkdownToPdf.csproj \
--configuration Release \
--no-build \
--output ./artifacts
--output ./artifacts \
-p:PackageVersion=${{ steps.versioning.outputs.VERSION }}

- name: List packages
run: ls -la ./artifacts || true

- name: Publish to NuGet
if: ${{ (github.event_name == 'push' && (startsWith(github.ref, 'refs/tags/') || github.ref == 'refs/heads/main')) || (github.event_name == 'workflow_dispatch' && github.event.inputs.publish == 'true') }} && env.NUGET_API_KEY != ''
# Cleaned up the logic: logic must be entirely inside the ${{ }} expression
if: ${{ ( (github.event_name == 'push' && (startsWith(github.ref, 'refs/tags/v') || github.ref == 'refs/heads/main')) || (github.event_name == 'workflow_dispatch' && github.event.inputs.publish == 'true') ) && env.NUGET_API_KEY != '' }}
run: |
echo "Pushing packages to NuGet.org"
echo "Pushing packages to NuGet.org with version ${{ steps.versioning.outputs.VERSION }}"
dotnet nuget push "./artifacts/*.nupkg" \
--api-key $NUGET_API_KEY \
--api-key ${{ secrets.NUGET_API_KEY }} \
--source https://api.nuget.org/v3/index.json \
--skip-duplicate
--skip-duplicate
24 changes: 24 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": ".NET Core Launch (console)",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
"program": "${workspaceFolder}/Tests/bin/Debug/net10.0/Tests.dll",
"args": [],
"cwd": "${workspaceFolder}/Tests",
"console": "internalConsole",
"stopAtEntry": false
},
{
"name": ".NET Core Attach",
"type": "coreclr",
"request": "attach"
}
]
}
41 changes: 41 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"version": "2.0.0",
"tasks": [
{
"label": "build",
"command": "dotnet",
"type": "process",
"args": [
"build",
"${workspaceFolder}/Tests/Tests.csproj",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary;ForceNoAlign"
],
"problemMatcher": "$msCompile"
},
{
"label": "publish",
"command": "dotnet",
"type": "process",
"args": [
"publish",
"${workspaceFolder}/Tests/Tests.csproj",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary;ForceNoAlign"
],
"problemMatcher": "$msCompile"
},
{
"label": "watch",
"command": "dotnet",
"type": "process",
"args": [
"watch",
"run",
"--project",
"${workspaceFolder}/Tests/Tests.csproj"
],
"problemMatcher": "$msCompile"
}
]
}
55 changes: 0 additions & 55 deletions DemoHighlight/DemoHighlighter.csproj

This file was deleted.

35 changes: 0 additions & 35 deletions DemoHighlight/Properties/AssemblyInfo.cs

This file was deleted.

13 changes: 13 additions & 0 deletions DemoHighlighter/DemoHighlighter.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net10.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\MarkdownToPdf\MarkdownToPdf.csproj" />
</ItemGroup>

</Project>
12 changes: 6 additions & 6 deletions DemoHighlight/Highlighter.cs → DemoHighlighter/Highlighter.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using Orionsoft.MarkdownToPdfLib.Converters;
using Orionsoft.MarkdownToPdfLib.Plugins;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing;
using System.Text.RegularExpressions;
using VectorAi.MarkdownToPdf.Converters;
using VectorAi.MarkdownToPdf.Converters.InlineConverters;
using VectorAi.MarkdownToPdf.Plugins;

namespace DemoHighlighter
{
Expand Down Expand Up @@ -42,7 +42,7 @@ public HighlightingPluginResult Convert(List<string> lines, IElementConverter co
var pos = 0;
while (pos < l.Length)
{
Match bestMatch = null;
Match? bestMatch = null;
var bestOffset = l.Length + 1;
var bestId = "";

Expand Down Expand Up @@ -81,4 +81,4 @@ public HighlightingPluginResult Convert(List<string> lines, IElementConverter co
return new HighlightingPluginResult { Spans = spans, Success = true, Background = Color.FromArgb(255, 0xf5, 0xf2, 0xf0) };
}
}
}
}
87 changes: 36 additions & 51 deletions DemoImagePlugin/DemoImagePlugin.cs
Original file line number Diff line number Diff line change
@@ -1,73 +1,58 @@
using Orionsoft.MarkdownToPdfLib.Converters;
using Orionsoft.MarkdownToPdfLib.Plugins;
using System;
using VectorAi.MarkdownToPdf.Converters;
using VectorAi.MarkdownToPdf.Plugins;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
using System.Windows.Media.Imaging;
using WpfMath;

namespace DemoImagePlugin
namespace DemoImagePlugin;

public class DemoImagePlugin : IImagePlugin
{
public class DemoImagePlugin : IImagePlugin
{
private string data;
private IElementConverter converter;
private string? data;
private IElementConverter? converter;

public ImagePluginResult Convert(string data, IElementConverter converter)
{
this.data = data;
this.converter = converter;
public ImagePluginResult Convert(string data, IElementConverter converter)
{
this.data = data;
this.converter = converter;

if (converter.Attributes?.Info == "math") return Math();
return SomeImagePlugin();
}
if (converter.Attributes?.Info == "math") return Math();
return SomeImagePlugin();
}

private static ImagePluginResult SomeImagePlugin()
{
private static ImagePluginResult SomeImagePlugin()
{
#if DEBUG
var fileName = Guid.NewGuid().ToString() + ".png";
var fileName = Guid.NewGuid().ToString() + ".png";
#else
var fileName = System.IO.Path.GetTempPath() + Guid.NewGuid().ToString() + ".png";
var fileName = System.IO.Path.GetTempPath() + Guid.NewGuid().ToString() + ".png";
#endif

var w = 100;
var h = 100;
using (var bitmap = new Bitmap(w, h))
var w = 100;
var h = 100;
using (var bitmap = new Bitmap(w, h))
{
bitmap.SetResolution(600, 600);
using (Graphics g = Graphics.FromImage(bitmap))
{
bitmap.SetResolution(600, 600);
using (Graphics g = Graphics.FromImage(bitmap))
{
g.DrawLine(Pens.Black, 0, 0, w - 1, h - 1);
g.DrawLine(Pens.Black, w - 1, 0, 0, h - 1);
}

bitmap.Save(fileName, ImageFormat.Png);
g.DrawLine(Pens.Black, 0, 0, w - 1, h - 1);
g.DrawLine(Pens.Black, w - 1, 0, 0, h - 1);
}
return new ImagePluginResult { FileName = fileName, Success = true };

bitmap.Save(fileName, ImageFormat.Png);
}
return new ImagePluginResult { FileName = fileName, Success = true };
}

private ImagePluginResult Math()
{
private ImagePluginResult Math()
{
#if DEBUG
var fileName = Guid.NewGuid().ToString() + ".png";
var fileName = Guid.NewGuid().ToString() + ".png";
#else
var fileName = System.IO.Path.GetTempPath() + Guid.NewGuid().ToString() + ".png";
var fileName = System.IO.Path.GetTempPath() + Guid.NewGuid().ToString() + ".png";
#endif

var parser = new TexFormulaParser();
var formula = parser.Parse(data);
var scale = converter.Parent.FontSize;
var renderer = formula.GetRenderer(TexStyle.Display, scale, "Arial");
var bitmapSource = renderer.RenderToBitmap(0.0, 0.0, 600);
// TODO: Find a way to convert LaTeX to a PNG image

var encoder = new PngBitmapEncoder();
encoder.Frames.Add(BitmapFrame.Create(bitmapSource));
using (var target = new FileStream(fileName, FileMode.Create))
{
encoder.Save(target);
}
return new ImagePluginResult { FileName = fileName, Success = true };
}
return new ImagePluginResult { FileName = fileName, Success = true };
}
}
Loading