Skip to content

Commit

Permalink
Merge pull request #174 from gaelj/release
Browse files Browse the repository at this point in the history
Release 0.8.5
  • Loading branch information
gaelj authored Apr 8, 2024
2 parents a383716 + 8599662 commit 5084da5
Show file tree
Hide file tree
Showing 15 changed files with 60 additions and 10 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
# Changelog

## 0.8.5 - 2024-04-09

### ✨ Introduce new features

- Allow opening markdown links by passing them as query parameter value to a viewer URL + query parameter name + '='

### 🐛 Fix a bug

- Update images when bath path for links is initially set
- Update links when bath path for links is initially set

## 0.8.4 - 2024-04-08

### 🐛 Fix a bug
Expand Down
2 changes: 1 addition & 1 deletion CodeMirror6/CodeMirror6.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<AssemblyName>GaelJ.BlazorCodeMirror6</AssemblyName>
<IsPackable>true</IsPackable>
<PackageId>GaelJ.BlazorCodeMirror6</PackageId>
<Version>0.8.4</Version>
<Version>0.8.5</Version>
<IncludeSymbols>true</IncludeSymbols>
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
Expand Down
1 change: 1 addition & 0 deletions CodeMirror6/CodeMirror6Wrapper.razor
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
ScrollPastEnd="@ScrollPastEnd"
ShowMarkdownControlCharactersAroundCursor="@ShowMarkdownControlCharactersAroundCursor"
BasePathForLinks="@BasePathForLinks"
MarkdownViewPath="@MarkdownViewPath"
/>
</ChildContent>
<ErrorContent Context="c">
Expand Down
5 changes: 5 additions & 0 deletions CodeMirror6/CodeMirror6Wrapper.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,11 @@ public partial class CodeMirror6Wrapper : ComponentBase
/// <value></value>
[Parameter] public string? BasePathForLinks { get; set; }
/// <summary>
/// The URL to the markdown viewer page, to optionally handle links to Markdown files. The original link will be appended as a query string parameter value
/// </summary>
/// <value></value>
[Parameter] public string? MarkdownViewPath { get; set; }
/// <summary>
/// Whether to show the markdown control characters around the cursor
/// </summary>
[Parameter] public bool ShowMarkdownControlCharactersAroundCursor { get; init; } = true;
Expand Down
12 changes: 11 additions & 1 deletion CodeMirror6/CodeMirror6WrapperInternal.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,11 @@ public partial class CodeMirror6WrapperInternal : ComponentBase, IAsyncDisposabl
/// <value></value>
[Parameter] public string? BasePathForLinks { get; set; }
/// <summary>
/// The URL to the markdown viewer page, to optionally handle links to Markdown files. The original link will be appended as a query string parameter value
/// </summary>
/// <value></value>
[Parameter] public string? MarkdownViewPath { get; set; }
/// <summary>
/// Additional attributes to be applied to the container element
/// </summary>
[Parameter(CaptureUnmatchedValues = true)] public Dictionary<string, object>? AdditionalAttributes { get; set; }
Expand Down Expand Up @@ -304,7 +309,8 @@ protected override async Task OnInitializedAsync()
HighlightActiveLine,
ShowMarkdownControlCharactersAroundCursor,
EmbedUploadsAsDataUrls,
BasePathForLinks
BasePathForLinks,
MarkdownViewPath
);
try {
if (IsWASM)
Expand Down Expand Up @@ -478,6 +484,10 @@ protected override async Task OnParametersSetAsync()
Config.BasePathForLinks = BasePathForLinks;
updated = true;
}
if (Config.MarkdownViewPath != MarkdownViewPath) {
Config.MarkdownViewPath = MarkdownViewPath;
updated = true;
}
if (LifeCycleCancellationTokenSource.IsCancellationRequested) return;
if (updated)
await CmJsInterop.PropertySetters.SetConfiguration();
Expand Down
10 changes: 9 additions & 1 deletion CodeMirror6/Models/CodeMirrorConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ namespace GaelJ.BlazorCodeMirror6.Models;
/// <param name="showMarkdownControlCharactersAroundCursor"></param>
/// <param name="embedUploadsAsDataUrls"></param>
/// <param name="basePathForLinks"></param>
/// <param name="markdownViewPath"></param>
public class CodeMirrorConfiguration(
string? doc,
string? placeholder,
Expand Down Expand Up @@ -68,7 +69,8 @@ public class CodeMirrorConfiguration(
bool highlightActiveLine,
bool showMarkdownControlCharactersAroundCursor,
bool embedUploadsAsDataUrls,
string? basePathForLinks)
string? basePathForLinks,
string? markdownViewPath)
{
/// <summary>
/// The text to display in the editor
Expand Down Expand Up @@ -225,4 +227,10 @@ public class CodeMirrorConfiguration(
/// </summary>
/// <value></value>
[JsonPropertyName("basePathForLinks")] public string? BasePathForLinks { get; set; } = basePathForLinks;

/// <summary>
/// The URL to the markdown viewer page, to optionally handle links to Markdown files. The original link will be appended as a query string parameter value
/// </summary>
/// <value></value>
[JsonPropertyName("markdownViewPath")] public string? MarkdownViewPath { get; set; } = markdownViewPath;
}
1 change: 1 addition & 0 deletions CodeMirror6/NodeLib/src/CmConfiguration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export class CmConfiguration {
public highlightActiveLine: boolean
public showMarkdownControlCharactersAroundCursor: boolean
public basePathForLinks: string | null
public markdownViewPath: string | null
}

export interface UnifiedMergeConfig {
Expand Down
7 changes: 7 additions & 0 deletions CodeMirror6/NodeLib/src/CmHyperlink.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export interface HyperLinkState
at: number;
url: string;
baseUrl?: string;
viewer?: string;
}

class HyperLinkIcon extends WidgetType
Expand All @@ -41,6 +42,8 @@ class HyperLinkIcon extends WidgetType
}
else
link.href = `${this.state.baseUrl}${this.state.url}`;
if (link.href.endsWith('.md') && this.state.viewer)
link.href = `${this.state.viewer}${encodeURIComponent(link.href)}`;
link.target = '_blank';
link.innerHTML = linkSvgImage;
link.className = 'cm-hyper-link-icon';
Expand All @@ -57,6 +60,9 @@ function hyperLinkDecorations(view: EditorView, id: string)
const basePathForLinks = (CMInstances[id] !== undefined && CMInstances[id].config.basePathForLinks)
? CMInstances[id].config.basePathForLinks.replace(/\/+$/, '') + "/"
: '';
const markdownViewPath = (CMInstances[id] !== undefined && CMInstances[id].config.markdownViewPath)
? CMInstances[id].config.markdownViewPath
: '';

while ((match = anyLinkRegexp.exec(doc)) !== null) {
const from = match.index;
Expand All @@ -66,6 +72,7 @@ function hyperLinkDecorations(view: EditorView, id: string)
at: to,
url: match[0],
baseUrl: basePathForLinks,
viewer: markdownViewPath,
}),
side: 1,
});
Expand Down
1 change: 1 addition & 0 deletions CodeMirror6/NodeLib/src/CmInstance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export class CmInstance
public drawSelectionCompartment: Compartment = new Compartment
public dropCursorCompartment: Compartment = new Compartment
public scrollPastEndCompartment: Compartment = new Compartment
public hyperLinksCompartment: Compartment = new Compartment
}

export const CMInstances: { [id: string]: CmInstance} = {}
5 changes: 3 additions & 2 deletions CodeMirror6/NodeLib/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ export async function initCodeMirror(
CMInstances[id].dropCursorCompartment.of(initialConfig.dropCursor ? dropCursor() : []),
CMInstances[id].scrollPastEndCompartment.of(initialConfig.scrollPastEnd ? scrollPastEnd() : []),
CMInstances[id].highlightActiveLineCompartment.of(initialConfig.highlightActiveLine ? highlightActiveLine() : []),
hyperLink(id),
CMInstances[id].hyperLinksCompartment.of(hyperLink(id)),

EditorView.updateListener.of(async (update) => { await updateListenerExtension(id, update) }),
linter(async view => maxDocLengthLintSource(id, view)),
Expand Down Expand Up @@ -377,7 +377,7 @@ export async function setConfiguration(id: string, newConfig: CmConfiguration) {
else
unfoldAll(CMInstances[id].view)
}
if (oldConfig.autoFormatMarkdown !== newConfig.autoFormatMarkdown || oldConfig.previewImages !== newConfig.previewImages) {
if (oldConfig.autoFormatMarkdown !== newConfig.autoFormatMarkdown || oldConfig.previewImages !== newConfig.previewImages || oldConfig.basePathForLinks !== newConfig.basePathForLinks) {
effects.push(CMInstances[id].markdownStylingCompartment.reconfigure(autoFormatMarkdownExtensions(id, newConfig.autoFormatMarkdown)))
if (newConfig.languageName === "Markdown" && newConfig.autoFormatMarkdown)
foldMarkdownDiagramCodeBlocks(CMInstances[id].view)
Expand All @@ -399,6 +399,7 @@ export async function setConfiguration(id: string, newConfig: CmConfiguration) {
if (oldConfig.dropCursor !== newConfig.dropCursor) effects.push(CMInstances[id].dropCursorCompartment.reconfigure(newConfig.dropCursor ? dropCursor() : []))
if (oldConfig.scrollPastEnd !== newConfig.scrollPastEnd) effects.push(CMInstances[id].scrollPastEndCompartment.reconfigure(newConfig.scrollPastEnd ? scrollPastEnd() : []))
if (oldConfig.highlightActiveLine !== newConfig.highlightActiveLine) effects.push(CMInstances[id].highlightActiveLineCompartment.reconfigure(newConfig.highlightActiveLine ? highlightActiveLine() : []))
if (oldConfig.basePathForLinks !== newConfig.basePathForLinks || oldConfig.markdownViewPath != newConfig.markdownViewPath) effects.push(CMInstances[id].hyperLinksCompartment.reconfigure(hyperLink(id)))

CMInstances[id].config = newConfig
if (effects.length > 0 || changes.length > 0)
Expand Down
2 changes: 1 addition & 1 deletion Examples.BlazorServer/Examples.BlazorServer.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>
<ImplicitUsings>enable</ImplicitUsings>
<Version>0.8.4</Version>
<Version>0.8.5</Version>
</PropertyGroup>
<ItemGroup>
<SupportedPlatform Include="browser" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<IsPackable>false</IsPackable>
<Version>0.8.4</Version>
<Version>0.8.5</Version>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Sentry.AspNetCore" Version="4.1.0" />
Expand Down
2 changes: 1 addition & 1 deletion Examples.BlazorWasm/Examples.BlazorWasm.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<IsPackable>false</IsPackable>
<Version>0.8.4</Version>
<Version>0.8.5</Version>
</PropertyGroup>
<ItemGroup>
<SupportedPlatform Include="browser-wasm" />
Expand Down
2 changes: 1 addition & 1 deletion Examples.Common/Examples.Common.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>
<Version>0.8.4</Version>
<Version>0.8.5</Version>
</PropertyGroup>
<ItemGroup>
<SupportedPlatform Include="browser" />
Expand Down
7 changes: 6 additions & 1 deletion NEW_CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
### ✨ Introduce new features

- Allow opening markdown links by passing them as query parameter value to a viewer URL + query parameter name + '='

### 🐛 Fix a bug

- Ensure base path for images is read dynamically
- Update images when bath path for links is initially set
- Update links when bath path for links is initially set

0 comments on commit 5084da5

Please sign in to comment.