-
-
Notifications
You must be signed in to change notification settings - Fork 565
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added new markdown block. Fixes #1744
- Loading branch information
Showing
18 changed files
with
189 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
30 changes: 30 additions & 0 deletions
30
core/Piranha.Manager/assets/src/js/components/blocks/markdown-block.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<template> | ||
<div class="block-body" :class="{ empty: isEmpty }"> | ||
<markdown-field :uid="uid" :model="model.body" /> | ||
</div> | ||
</template> | ||
|
||
<script> | ||
export default { | ||
props: ["uid", "model"], | ||
methods: { | ||
onBlur: function (e) { | ||
// Tell parent that title has been updated | ||
var title = this.model.body.value.replace(/(<([^>]+)>)/ig, ""); | ||
if (title.length > 40) { | ||
title = title.substring(0, 40) + "..."; | ||
} | ||
this.$emit('update-title', { | ||
uid: this.uid, | ||
title: title | ||
}); | ||
} | ||
}, | ||
computed: { | ||
isEmpty: function () { | ||
return piranha.utils.isEmptyText(this.model.body.value); | ||
} | ||
} | ||
} | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/* | ||
* Copyright (c) .NET Foundation and Contributors | ||
* | ||
* This software may be modified and distributed under the terms | ||
* of the MIT license. See the LICENSE file for details. | ||
* | ||
* https://github.com/piranhacms/piranha.core | ||
* | ||
*/ | ||
|
||
using System.Text.RegularExpressions; | ||
using Piranha.Extend.Fields; | ||
|
||
namespace Piranha.Extend.Blocks | ||
{ | ||
/// <summary> | ||
/// Single column HTML block. | ||
/// </summary> | ||
[BlockType(Name = "Markdown", Category = "Content", Icon = "fab fa-markdown", Component = "markdown-block")] | ||
public class MarkdownBlock : Block, ISearchable, ITranslatable | ||
{ | ||
/// <summary> | ||
/// Gets/sets the Markdown body. | ||
/// </summary> | ||
public MarkdownField Body { get; set; } | ||
|
||
/// <summary> | ||
/// Gets the title of the block when used in a block group. | ||
/// </summary> | ||
/// <returns>The title</returns> | ||
public override string GetTitle() | ||
{ | ||
if (Body?.Value != null) | ||
{ | ||
var html = App.Markdown.Transform(Body.Value); | ||
|
||
var title = Regex.Replace(html, @"<[^>]*>", ""); | ||
|
||
if (title.Length > 40) | ||
{ | ||
title = title.Substring(0, 40) + "..."; | ||
} | ||
return title; | ||
} | ||
return "Empty"; | ||
} | ||
|
||
/// <summary> | ||
/// Gets the content that should be indexed for searching. | ||
/// </summary> | ||
public string GetIndexedContent() | ||
{ | ||
return !string.IsNullOrEmpty(Body.Value) ? Body.Value : ""; | ||
} | ||
|
||
/// <summary> | ||
/// Implicitly converts the markdown block to a HTML string. | ||
/// </summary> | ||
/// <param name="block">The block</param> | ||
public static implicit operator string(MarkdownBlock block) | ||
{ | ||
return App.Markdown.Transform(block.Body?.Value); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
@model Piranha.Extend.Blocks.HtmlBlock | ||
|
||
<div class="block"> | ||
@Html.Raw(Model.Body) | ||
@Html.Raw(Model) | ||
</div> |
5 changes: 5 additions & 0 deletions
5
examples/RazorWeb/Pages/DisplayTemplates/MarkdownBlock.cshtml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
@model Piranha.Extend.Blocks.MarkdownBlock | ||
|
||
<div class="block"> | ||
@Html.Raw(Model) | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
@model Piranha.Extend.Blocks.TextBlock | ||
|
||
<div class="block"> | ||
@Model.Body | ||
@Model | ||
</div> |