render pages

This commit is contained in:
Paul Schneider 2023-04-08 01:39:37 +01:00
commit ca92867243
14 changed files with 126 additions and 124 deletions

View file

@ -8,13 +8,13 @@ using System.Linq.Expressions;
namespace Yavsc.Helpers namespace Yavsc.Helpers
{ {
public static class AsciiDocHelpers public static class AsciiDocHelpers
{
static void ToHtml(this IElement elt, IHtmlContentBuilder contentbuilder)
{ {
switch (elt.GetType().FullName) static void ToHtml(this IElement elt, IHtmlContentBuilder contentbuilder)
{ {
case "AsciiDocNet.Paragraph": switch (elt.GetType().FullName)
Paragraph p = (Paragraph) elt; {
case "AsciiDocNet.Paragraph":
Paragraph p = (Paragraph)elt;
contentbuilder.AppendHtmlLine("<p>"); contentbuilder.AppendHtmlLine("<p>");
foreach (var pitem in p) foreach (var pitem in p)
{ {
@ -23,8 +23,8 @@ namespace Yavsc.Helpers
contentbuilder.AppendHtmlLine("</p>"); contentbuilder.AppendHtmlLine("</p>");
break; break;
case "AsciiDocNet.SectionTitle": case "AsciiDocNet.SectionTitle":
SectionTitle stitle = (SectionTitle) elt; SectionTitle stitle = (SectionTitle)elt;
contentbuilder.AppendHtmlLine($"<h{stitle.Level}>"); contentbuilder.AppendHtmlLine($"<h{stitle.Level}>");
foreach (var titem in stitle) foreach (var titem in stitle)
{ {
@ -33,123 +33,124 @@ namespace Yavsc.Helpers
contentbuilder.AppendHtmlLine("</h>"); contentbuilder.AppendHtmlLine("</h>");
break; break;
case "AsciiDocNet.UnorderedList": case "AsciiDocNet.UnorderedList":
UnorderedList ul = (UnorderedList) elt; UnorderedList ul = (UnorderedList)elt;
contentbuilder.AppendHtmlLine("<ul>"); contentbuilder.AppendHtmlLine("<ul>");
foreach (var li in ul.Items) foreach (var li in ul.Items)
{ {
contentbuilder.AppendHtmlLine("<li>"); contentbuilder.AppendHtmlLine("<li>");
foreach (var lii in li) foreach (var lii in li)
{ {
lii.ToHtml(contentbuilder); lii.ToHtml(contentbuilder);
} }
contentbuilder.AppendHtmlLine("</li>"); contentbuilder.AppendHtmlLine("</li>");
} }
contentbuilder.AppendHtmlLine("</ul>"); contentbuilder.AppendHtmlLine("</ul>");
break; break;
case "AsciiDocNet.Source": case "AsciiDocNet.Source":
Source source = (Source) elt ; Source source = (Source)elt;
// TODO syntact hilighting and fun js modules // TODO syntact hilighting and fun js modules
contentbuilder.AppendHtmlLine("<pre><code>"); contentbuilder.AppendHtmlLine("<pre><code>");
contentbuilder.Append(source.Text); contentbuilder.Append(source.Text);
contentbuilder.AppendHtmlLine("</code></pre>"); contentbuilder.AppendHtmlLine("</code></pre>");
break; break;
default: default:
string unsupportedType = elt.GetType().FullName; string unsupportedType = elt.GetType().FullName;
throw new InvalidProgramException(unsupportedType); throw new InvalidProgramException(unsupportedType);
}
}
static void ToHtml(this IInlineElement elt, IHtmlContentBuilder sb)
{
switch (elt.GetType().FullName)
{
case "AsciiDocNet.Link":
Link link = (Link) elt;
sb.AppendFormat("<a href=\"{0}\">{1}</a> ",link.Href, link.Text);
break;
case "AsciiDocNet.TextLiteral":
sb.Append(elt.ToString());
break;
case "AsciiDocNet.Emphasis":
sb.AppendHtml("<i>");
AsciiDocNet.Emphasis em = (Emphasis) elt;
sb.Append(em.Text);
sb.AppendHtml("</i>");
break;
case "AsciiDocNet.Strong":
sb.AppendHtml("<b>");
AsciiDocNet.Strong str = (Strong) elt;
foreach (var stritem in str)
{
stritem.ToHtml(sb);
}
sb.AppendHtml("</b>");
break;
default:
string unsupportedType = elt.GetType().FullName;
throw new InvalidProgramException(unsupportedType);
}
}
public static IHtmlContent ToHtml(this Document doc, int doclevel = 4)
{
var contentbuilder = new HtmlContentBuilder();
if (doc.Title != null)
{
if (!string.IsNullOrWhiteSpace(doc.Title.Title))
{
contentbuilder.AppendHtmlLine($"<h{doclevel}>{doc.Title.Title}</h{doclevel}>");
if (!string.IsNullOrWhiteSpace(doc.Title.Subtitle))
{
contentbuilder.AppendHtmlLine($"<i>{doc.Title.Title}</i><br/>");
}
} }
} }
foreach (var item in doc)
static void ToHtml(this IInlineElement elt, IHtmlContentBuilder sb)
{ {
item.ToHtml(contentbuilder); switch (elt.GetType().FullName)
{
case "AsciiDocNet.Link":
Link link = (Link)elt;
sb.AppendFormat("<a href=\"{0}\">{1}</a> ", link.Href, link.Text);
break;
case "AsciiDocNet.TextLiteral":
sb.Append(elt.ToString());
break;
case "AsciiDocNet.Emphasis":
sb.AppendHtml("<i>");
AsciiDocNet.Emphasis em = (Emphasis)elt;
sb.Append(em.Text);
sb.AppendHtml("</i>");
break;
case "AsciiDocNet.Strong":
sb.AppendHtml("<b>");
AsciiDocNet.Strong str = (Strong)elt;
foreach (var stritem in str)
{
stritem.ToHtml(sb);
}
sb.AppendHtml("</b>");
break;
default:
string unsupportedType = elt.GetType().FullName;
throw new InvalidProgramException(unsupportedType);
}
}
public static IHtmlContent ToHtml(this Document doc, int doclevel = 4)
{
var contentbuilder = new HtmlContentBuilder();
if (doc.Title != null)
{
if (!string.IsNullOrWhiteSpace(doc.Title.Title))
{
contentbuilder.AppendHtmlLine($"<h{doclevel}>{doc.Title.Title}</h{doclevel}>");
if (!string.IsNullOrWhiteSpace(doc.Title.Subtitle))
{
contentbuilder.AppendHtmlLine($"<i>{doc.Title.Title}</i><br/>");
}
}
}
foreach (var item in doc)
{
item.ToHtml(contentbuilder);
}
return contentbuilder;
} }
return contentbuilder;
}
public static IHtmlContent AsciiDocFor<TModel>(this IHtmlHelper<TModel> html, public static IHtmlContent AsciiDocFor<TModel>(this IHtmlHelper<TModel> html,
Expression<Func<TModel, string>> expression) Expression<Func<TModel, string>> expression)
{ {
string ascii = html.ValueFor<string>(expression, "{0}"); string ascii = html.ValueFor<string>(expression, "{0}");
Document document = Document.Parse(ascii); if (string.IsNullOrWhiteSpace(ascii))
var htmlDoc = document.ToHtml(); return new HtmlString(string.Empty);
Document document = Document.Parse(ascii);
var htmlDoc = document.ToHtml();
var span = new TagBuilder("p") { TagRenderMode = TagRenderMode.SelfClosing };
span.InnerHtml.AppendHtml(htmlDoc);
return span.RenderBody();
}
var span = new TagBuilder("p") { TagRenderMode = TagRenderMode.SelfClosing }; public static string AsciiDoc(IHtmlHelper<BlogPost> htmlHelper, string text)
span.InnerHtml.AppendHtml(htmlDoc); {
return span.RenderBody(); return AsciiDoc(htmlHelper, text, null);
} }
public static string AsciiDoc(IHtmlHelper<BlogPost> htmlHelper, string text) private static string AsciiDoc(IHtmlHelper<BlogPost> htmlHelper, string text, object htmlAttributes)
{ {
return AsciiDoc(htmlHelper, text, null); // Create tag builder
} var builder = new TagBuilder("div");
var document = Document.Parse(text);
private static string AsciiDoc(IHtmlHelper<BlogPost> htmlHelper, string text, object htmlAttributes) // builder.InnerHtml = .
{
// Create tag builder
var builder = new TagBuilder("div");
var document = Document.Parse(text);
// builder.InnerHtml = . // Add attributes
builder.MergeAttribute("class", "ascii");
builder.MergeAttributes(new RouteValueDictionary(htmlAttributes));
// Add attributes // Render tag
builder.MergeAttribute("class", "ascii"); return builder.ToString();
builder.MergeAttributes(new RouteValueDictionary(htmlAttributes)); }
// Render tag
return builder.ToString();
} }
} }
}

View file

@ -9,8 +9,9 @@ namespace Yavsc.Helpers
public override async Task ProcessAsync (TagHelperContext context, TagHelperOutput output) public override async Task ProcessAsync (TagHelperContext context, TagHelperOutput output)
{ {
var content = await output.GetChildContentAsync(); var content = await output.GetChildContentAsync();
string text = content.GetContent();
Document document = Document.Parse(content.GetContent()); if (string.IsNullOrWhiteSpace(text)) return;
Document document = Document.Parse(text);
var html = document.ToHtml(4); var html = document.ToHtml(4);
using var stringWriter = new StringWriter(); using var stringWriter = new StringWriter();
html.WriteTo(stringWriter, HtmlEncoder.Default); html.WriteTo(stringWriter, HtmlEncoder.Default);

View file

@ -30,7 +30,7 @@
<img src="@item.Photo" class="blogphoto"></a> <img src="@item.Photo" class="blogphoto"></a>
</td> </td>
<td> <td>
<markdown>@((item.Content?.Length > 256) ? item.Content.Substring(0, 256) + " ..." : item.Content)</markdown> <asciidoc>@((item.Content?.Length > 256) ? item.Content.Substring(0, 256) + " ..." : item.Content)</asciidoc>
<span style="font-size:x-small;">(@item.Author.UserName </span>, <span style="font-size:x-small;">(@item.Author.UserName </span>,
<span style="font-size:xx-small;"> <span style="font-size:xx-small;">
posté le @item.DateCreated.ToString("dddd d MMM yyyy à H:mm") posté le @item.DateCreated.ToString("dddd d MMM yyyy à H:mm")

View file

@ -2,7 +2,7 @@
ViewData["Title"] = "Conditions Générales de Vente"; ViewData["Title"] = "Conditions Générales de Vente";
} }
<h2>@ViewData["Title"]</h2> <h2>@ViewData["Title"]</h2>
<markdown> <asciidoc>
Le paiement intervient à la commande, quelque soit la date d'intervention. Le paiement intervient à la commande, quelque soit la date d'intervention.
Vous pouvez annuler votre commande depuis la [liste de vos commande en cours](/HairCutCommand/), Vous pouvez annuler votre commande depuis la [liste de vos commande en cours](/HairCutCommand/),
@ -10,4 +10,4 @@ Vous pouvez annuler votre commande depuis la [liste de vos commande en cours](/H
Vous pouvez demander le remboursement d'un paiement, dans le cadre d'une réclamation sur l'execution Vous pouvez demander le remboursement d'un paiement, dans le cadre d'une réclamation sur l'execution
de votre commande, en nous contactant via courrier éléctronique ou postal, [que vour retrouverez sur la page de contact](/Home/Contact), votre demande sera rapidement traitée. de votre commande, en nous contactant via courrier éléctronique ou postal, [que vour retrouverez sur la page de contact](/Home/Contact), votre demande sera rapidement traitée.
</markdown> </asciidoc>

View file

@ -4,7 +4,7 @@
<h1>@ViewData["Title"]</h1> <h1>@ViewData["Title"]</h1>
<environment names="freefield,Development"> <environment names="freefield,Development">
<markdown> <asciidoc>
## O objetivo ## O objetivo
Esta aplicação é construída para conectar artistas Esta aplicação é construída para conectar artistas
@ -86,36 +86,36 @@ que imediatamente desativa as publicações associadas às suas informações,
e planeia a eliminação completa desta informação no prazo de quinze dias e planeia a eliminação completa desta informação no prazo de quinze dias
do aplicativo, a menos que seja um pedido contraditório. do aplicativo, a menos que seja um pedido contraditório.
A operação é anulável até duas semanas após a sua programação. A operação é anulável até duas semanas após a sua programação.
</markdown> </asciidoc>
</environment> </environment>
<environment names="Lua,Development"> <environment names="Lua,Development">
<markdown>Este é o meu site perso, uma configuração de _Yavsc_ (outro negócio muito pequeno). <asciidoc>Este é o meu site perso, uma configuração de _Yavsc_ (outro negócio muito pequeno).
* [README](https://github.com/pazof/yavsc/blob/vnext/README.md) * [README](https://github.com/pazof/yavsc/blob/vnext/README.md)
* [licença: GNU GPL v3](https://github.com/pazof/yavsc/blob/vnext/LICENSE) * [licença: GNU GPL v3](https://github.com/pazof/yavsc/blob/vnext/LICENSE)
Outras instalações: Outras instalações:
</markdown> </asciidoc>
<markdown> <asciidoc>
* [Coiffure](http://coiffure.pschneider.fr) * [Coiffure](http://coiffure.pschneider.fr)
* [ZicMoove](http://linkmuse.pschneider.fr) * [ZicMoove](http://linkmuse.pschneider.fr)
* [Yavsc](http://yavsc.pschneider.fr) * [Yavsc](http://yavsc.pschneider.fr)
</markdown> </asciidoc>
</environment> </environment>
<environment names="Yavsc"> <environment names="Yavsc">
<markdown> <asciidoc>
Yet Another Very Small Company ... Yet Another Very Small Company ...
* [README](https://github.com/pazof/yavsc/blob/vnext/README.md) * [README](https://github.com/pazof/yavsc/blob/vnext/README.md)
* [license: GNU FPL v3](https://github.com/pazof/yavsc/blob/vnext/LICENSE) * [license: GNU FPL v3](https://github.com/pazof/yavsc/blob/vnext/LICENSE)
</markdown> </asciidoc>
</environment> </environment>
<environment names="YavscPre"> <environment names="YavscPre">
<markdown> <asciidoc>
## Yet Another Very Small Company : ## Yet Another Very Small Company :
* [README](https://github.com/pazof/yavsc/blob/vnext/README.md) * [README](https://github.com/pazof/yavsc/blob/vnext/README.md)
* [license: GNU FPL v3](https://github.com/pazof/yavsc/blob/vnext/LICENSE) * [license: GNU FPL v3](https://github.com/pazof/yavsc/blob/vnext/LICENSE)
@ -125,12 +125,12 @@ En production:
* [Lua](https://lua.pschneider.fr) * [Lua](https://lua.pschneider.fr)
* [Yavsc](https://yavsc.pschneider.fr) * [Yavsc](https://yavsc.pschneider.fr)
</markdown> </asciidoc>
</environment> </environment>
<environment names="coiffure"> <environment names="coiffure">
<markdown> <asciidoc>
Você está no site da ordem em cabeleireiro em casa de Soraya Boudjouraf, Você está no site da ordem em cabeleireiro em casa de Soraya Boudjouraf,
um ás de cabeleireiro, que trabalha na região de Paris. um ás de cabeleireiro, que trabalha na região de Paris.
@ -138,11 +138,11 @@ Ao validar um formulário de pedido aqui, é para ela que você notifica sua sol
Você pode [Deixe-lhe o seu número de telefone] (/ HairCutCommand / HairCut? ActivityCode = Brush & performerId = 1bd841ab-c305-4971-940d-7ddca818310c) Você pode [Deixe-lhe o seu número de telefone] (/ HairCutCommand / HairCut? ActivityCode = Brush & performerId = 1bd841ab-c305-4971-940d-7ddca818310c)
e / ou detalhes sobre o seu pedido, e / ou detalhes sobre o seu pedido,
ela vai ligar de volta.</markdown> ela vai ligar de volta.</asciidoc>
</environment> </environment>
<environment names="Development"> <environment names="Development">
<markdown> <asciidoc>
## Este é um site de desenvolvimento. ## Este é um site de desenvolvimento.
Este recurso só diz respeito ao desenvolvimento do software que o implementa. Este recurso só diz respeito ao desenvolvimento do software que o implementa.
@ -155,7 +155,7 @@ A "pré-produção" exibe os seguintes sites:
* [Yavsc](https://yavsc.pschneider.fr) * [Yavsc](https://yavsc.pschneider.fr)
* [Lua](https://lua.pschneider.fr) * [Lua](https://lua.pschneider.fr)
</markdown> </asciidoc>
</environment> </environment>
<p> <p>

View file

@ -3,7 +3,7 @@
} }
<h1>@ViewData["Title"]</h1> <h1>@ViewData["Title"]</h1>
<markdown> <asciidoc>
# Blog et fichiers utilisateurs # Blog et fichiers utilisateurs
@ -35,4 +35,4 @@ Et ils possèdent une addresse permanente de la forme :
</markdown> </asciidoc>

View file

@ -3,7 +3,7 @@
} }
<h1>@ViewData["Title"]</h1> <h1>@ViewData["Title"]</h1>
<markdown> <asciidoc>
Quelques extensions à un Markdown de base : Quelques extensions à un Markdown de base :
* les video et audio: `![video: Ep. 28 - La France en commun - Une invitation à écrire un nouveau projet d'émancipation humaine](/images/testVideo.mp4)` * les video et audio: `![video: Ep. 28 - La France en commun - Une invitation à écrire un nouveau projet d'émancipation humaine](/images/testVideo.mp4)`
@ -16,4 +16,4 @@ Quelques extensions à un Markdown de base :
* le tag "Titre d'article": "#1_great_title" * le tag "Titre d'article": "#1_great_title"
* le tag "User" = "@@(John Doe)" ou "@@jdoe" * le tag "User" = "@@(John Doe)" ou "@@jdoe"
</markdown> </asciidoc>

View file

@ -2,7 +2,7 @@
ViewData["Title"] = "Conditions Générales de Vente"; ViewData["Title"] = "Conditions Générales de Vente";
} }
<h2>@ViewData["Title"]</h2> <h2>@ViewData["Title"]</h2>
<markdown> <asciidoc>
Le paiement intervient à la commande, quelque soit la date d'intervention. Le paiement intervient à la commande, quelque soit la date d'intervention.
Vous pouvez annuler votre commande depuis la [liste de vos commande en cours](/HairCutCommand/), Vous pouvez annuler votre commande depuis la [liste de vos commande en cours](/HairCutCommand/),
@ -10,4 +10,4 @@ Vous pouvez annuler votre commande depuis la [liste de vos commande en cours](/H
Vous pouvez demander le remboursement d'un paiement, dans le cadre d'une réclamation sur l'execution Vous pouvez demander le remboursement d'un paiement, dans le cadre d'une réclamation sur l'execution
de votre commande, en nous contactant via courrier éléctronique ou postal, [que vour retrouverez sur la page de contact](/Home/Contact), votre demande sera rapidement traitée. de votre commande, en nous contactant via courrier éléctronique ou postal, [que vour retrouverez sur la page de contact](/Home/Contact), votre demande sera rapidement traitée.
</markdown> </asciidoc>

View file

@ -3,7 +3,7 @@
} }
<h1>@ViewData["Title"]</h1> <h1>@ViewData["Title"]</h1>
<markdown> <asciidoc>
## La confidentialité ## La confidentialité
À aucun moment, aucune adresse postale, aucune adresse e-mail ni aucun numéro de téléphone À aucun moment, aucune adresse postale, aucune adresse e-mail ni aucun numéro de téléphone
@ -11,4 +11,4 @@ ne sont transmis à personne. Seul le système et son [possesseur](/Home/Contact
De plus, le droit de retrait est permanent et sa mise en oeuvre [immédiate](/Account/Delete). De plus, le droit de retrait est permanent et sa mise en oeuvre [immédiate](/Account/Delete).
</markdown> </asciidoc>

View file

@ -4,14 +4,14 @@
<h1>@ViewData["Title"]</h1> <h1>@ViewData["Title"]</h1>
<em>Linkmuse(trox)</em> <em>Linkmuse(trox)</em>
<markdown> <asciidoc>
Les tags. Les tags.
La librairie, les lives. La librairie, les lives.
</markdown> </asciidoc>
@{ @{
ViewData["Title"] = @SR["TODO"]; ViewData["Title"] = @SR["TODO"];
} }
<h1>@ViewData["Title"]</h1> <h1>@ViewData["Title"]</h1>
<em>Faster, stronger, shorter</em> <em>Faster, stronger, shorter</em>
<markdown> <asciidoc>
</markdown> </asciidoc>

View file

@ -32,7 +32,7 @@
<img src="@item.Photo" class="blogphoto"></a> <img src="@item.Photo" class="blogphoto"></a>
</td> </td>
<td> <td>
<markdown summary="256">@item.Content</markdown> <asciidoc summary="256">@item.Content</asciidoc>
@if (trunked) { <a asp-action="Details" asp-route-id="@item.Id" class="bloglink">...</a> } @if (trunked) { <a asp-action="Details" asp-route-id="@item.Id" class="bloglink">...</a> }
<span style="font-size:x-small;">(@item.Author.UserName </span>, <span style="font-size:x-small;">(@item.Author.UserName </span>,
<span style="font-size:xx-small;"> <span style="font-size:xx-small;">

View file

@ -1,7 +1,7 @@
@model Comment @model Comment
<div data-type="blogcomment" data-id="@Model.Id" data-allow-edit="@(User.GetUserId()==Model.AuthorId?"true":"false")" <div data-type="blogcomment" data-id="@Model.Id" data-allow-edit="@(User.GetUserId()==Model.AuthorId?"true":"false")"
data-allow-moderate="@ViewData["moderatoFlag"]" data-date="@Html.Raw(Model.DateCreated)" data-username="@Model.Author.UserName" > data-allow-moderate="@ViewData["moderatoFlag"]" data-date="@Html.Raw(Model.DateCreated)" data-username="@Model.Author.UserName" >
<markdown>@Model.Content</markdown> <asciidoc>@Model.Content</asciidoc>
<div class="subcomments"> <div class="subcomments">
@if (Model.Children!=null && Model.Children.Count>0) { @if (Model.Children!=null && Model.Children.Count>0) {
foreach (var comment in Model.Children) { foreach (var comment in Model.Children) {

View file

@ -64,7 +64,7 @@
<div class="alert alert-info alert-dismissable"> <div class="alert alert-info alert-dismissable">
<img src="~/images/Notifications/@(n.icon).png" style="max-height:3em; float: left; margin:1em;"/> <h2 markdown="@n.title"></h2> <img src="~/images/Notifications/@(n.icon).png" style="max-height:3em; float: left; margin:1em;"/> <h2 markdown="@n.title"></h2>
<a class="close" data-dismiss="alert" aria-label="close" onclick="notifClick(@n.Id)">@((n.click_action==null)?SR["Fermer"]:SR[n.click_action])</a> <a class="close" data-dismiss="alert" aria-label="close" onclick="notifClick(@n.Id)">@((n.click_action==null)?SR["Fermer"]:SR[n.click_action])</a>
<markdown>@n.body</markdown> <asciidoc>@n.body</asciidoc>
</div>} </div>}
} }

View file

@ -1,4 +1,4 @@
<markdown> <asciidoc>
# Title # Title
@ -20,4 +20,4 @@
Or else, ![input:textarea:yours](enter you life here :-)) Or else, ![input:textarea:yours](enter you life here :-))
</markdown> </asciidoc>