From 1f81355afd96e6cdbb1889930c7b2a5a92fe73e6 Mon Sep 17 00:00:00 2001 From: Sebastien Ros Date: Mon, 17 Feb 2014 17:15:37 -0800 Subject: [PATCH] Improving Markdown support - Adding a settings page to enable Markdown on Blogs - Improving live preview Markdown styles --- .../MarkdownSiteSettingsPartHandler.cs | 50 +++++ .../Modules/Markdown/Markdown.csproj | 6 + .../Modules/Markdown/Migrations.cs | 11 + .../Models/MarkdownSiteSettingsPart.cs | 11 + .../Markdown/Styles/admin-markdown.css | 189 +++++++++++++----- .../Markdown.MarkdownSiteSettings.cshtml | 10 + 6 files changed, 224 insertions(+), 53 deletions(-) create mode 100644 src/Orchard.Web/Modules/Markdown/Handlers/MarkdownSiteSettingsPartHandler.cs create mode 100644 src/Orchard.Web/Modules/Markdown/Migrations.cs create mode 100644 src/Orchard.Web/Modules/Markdown/Models/MarkdownSiteSettingsPart.cs create mode 100644 src/Orchard.Web/Modules/Markdown/Views/EditorTemplates/Parts/Markdown.MarkdownSiteSettings.cshtml diff --git a/src/Orchard.Web/Modules/Markdown/Handlers/MarkdownSiteSettingsPartHandler.cs b/src/Orchard.Web/Modules/Markdown/Handlers/MarkdownSiteSettingsPartHandler.cs new file mode 100644 index 000000000..e4a15c45f --- /dev/null +++ b/src/Orchard.Web/Modules/Markdown/Handlers/MarkdownSiteSettingsPartHandler.cs @@ -0,0 +1,50 @@ +using System.Linq; +using Markdown.Models; +using Orchard.ContentManagement; +using Orchard.ContentManagement.Handlers; +using Orchard.ContentManagement.MetaData; +using Orchard.ContentManagement.MetaData.Builders; +using Orchard.Localization; + +namespace Markdown.Handlers { + public class MarkdownSiteSettingsPartHandler : ContentHandler { + private readonly IContentDefinitionManager _contentDefinitionManager; + + public MarkdownSiteSettingsPartHandler(IContentDefinitionManager contentDefinitionManager) { + _contentDefinitionManager = contentDefinitionManager; + Filters.Add(new ActivatingFilter("Site")); + Filters.Add(new TemplateFilterForPart("MarkdownSiteSettings", "Parts/Markdown.MarkdownSiteSettings", "markdown")); + OnInitializing((context, part) => { + part.UseMarkdownForBlogs = false; + }); + + OnUpdated((context, part) => { + var blogPost = _contentDefinitionManager.GetTypeDefinition("BlogPost"); + if (blogPost == null) { + return; + } + + var bodyPart = blogPost.Parts.FirstOrDefault(x => x.PartDefinition.Name == "BodyPart"); + if (bodyPart == null) { + return; + } + + _contentDefinitionManager.AlterTypeDefinition("BlogPost", build => build + .WithPart("BodyPart", cfg => cfg + .WithSetting("BodyTypePartSettings.Flavor", part.UseMarkdownForBlogs ? "markdown" : "html") + ) + ); + }); + + T = NullLocalizer.Instance; + } + + public Localizer T { get; set; } + protected override void GetItemMetadata(GetContentItemMetadataContext context) { + if (context.ContentItem.ContentType != "Site") + return; + base.GetItemMetadata(context); + context.Metadata.EditorGroupInfo.Add(new GroupInfo(T("Markdown"))); + } + } +} \ No newline at end of file diff --git a/src/Orchard.Web/Modules/Markdown/Markdown.csproj b/src/Orchard.Web/Modules/Markdown/Markdown.csproj index 51d51d5fb..b1acac739 100644 --- a/src/Orchard.Web/Modules/Markdown/Markdown.csproj +++ b/src/Orchard.Web/Modules/Markdown/Markdown.csproj @@ -119,6 +119,9 @@ + + + @@ -168,6 +171,9 @@ orchard-markdown.js + + + 10.0 $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) diff --git a/src/Orchard.Web/Modules/Markdown/Migrations.cs b/src/Orchard.Web/Modules/Markdown/Migrations.cs new file mode 100644 index 000000000..de1132acc --- /dev/null +++ b/src/Orchard.Web/Modules/Markdown/Migrations.cs @@ -0,0 +1,11 @@ +using Orchard.ContentManagement.MetaData; +using Orchard.Data.Migration; + +namespace Markdown { + public class Migrations : DataMigrationImpl { + + public int Create() { + return 1; + } + } +} \ No newline at end of file diff --git a/src/Orchard.Web/Modules/Markdown/Models/MarkdownSiteSettingsPart.cs b/src/Orchard.Web/Modules/Markdown/Models/MarkdownSiteSettingsPart.cs new file mode 100644 index 000000000..4db1145b2 --- /dev/null +++ b/src/Orchard.Web/Modules/Markdown/Models/MarkdownSiteSettingsPart.cs @@ -0,0 +1,11 @@ +using Orchard.ContentManagement; + +namespace Markdown.Models { + public class MarkdownSiteSettingsPart : ContentPart { + + public bool UseMarkdownForBlogs { + get { return this.Retrieve(x => x.UseMarkdownForBlogs); } + set { this.Store(x => x.UseMarkdownForBlogs, value); } + } + } +} \ No newline at end of file diff --git a/src/Orchard.Web/Modules/Markdown/Styles/admin-markdown.css b/src/Orchard.Web/Modules/Markdown/Styles/admin-markdown.css index 16d655ed9..97e0ed0e3 100644 --- a/src/Orchard.Web/Modules/Markdown/Styles/admin-markdown.css +++ b/src/Orchard.Web/Modules/Markdown/Styles/admin-markdown.css @@ -9,20 +9,19 @@ cursor: pointer; } -.wmd-button > span { - background-image: url(../Content/Admin/Images/wmd-buttons.png); - background-repeat: no-repeat; - background-position: 0 0; - width: 20px; - height: 20px; - display: inline-block; -} + .wmd-button > span { + background-image: url(../Content/Admin/Images/wmd-buttons.png); + background-repeat: no-repeat; + background-position: 0 0; + width: 20px; + height: 20px; + display: inline-block; + } -.wmd-button-row -{ - position: relative; +.wmd-button-row { + position: relative; margin: 10px 5px 5px 5px; - padding: 0; + padding: 0; height: 20px; } @@ -33,7 +32,7 @@ } #main .wmd-editor-box textarea.wmd-input { - display:block; + display: block; margin-bottom: 0; width: 97%; min-width: 400px; @@ -47,16 +46,19 @@ height: 400px; width: 99%; } + .wmd-innerbox { height: 100%; display: table-row; } + .wmd-editor-box { width: 49%; display: table-cell; height: 100%; vertical-align: top; } + .wmd-preview-box { width: 49%; display: table-cell; @@ -65,7 +67,7 @@ vertical-align: top; } -.wmd-preview { +.wmd-preview { border: 2px dotted #CCC; padding: 3px; margin-top: 34px; @@ -74,58 +76,139 @@ overflow-y: scroll; } -.wmd-preview ol { - list-style: decimal; - margin-left: 15px; -} + .wmd-preview ol { + list-style: decimal; + margin-left: 15px; + } -.wmd-preview ul { - list-style: disc; - margin-left: 15px; -} + .wmd-preview ul { + list-style: disc; + margin-left: 15px; + } -.wmd-preview blockquote { - margin: 1em 3em; - color: #333; - border-left: 2px solid #999; - padding-left: 1em; -} + .wmd-preview blockquote { + margin: 1em 3em; + color: #333; + border-left: 2px solid #999; + padding-left: 1em; + } -.wmd-preview pre, .wmd-preview code { - margin: 1em 3em; - color: #333; - border-left: 2px solid #999; - padding-left: 1em; - font-family: Courier New; -} + .wmd-preview pre, .wmd-preview code { + margin: 1em 3em; + color: #333; + border-left: 2px solid #999; + padding-left: 1em; + font-family: Courier New; + } -.wmd-preview pre code { - border: none; - margin-left: 0; - padding-left: 0; -} + .wmd-preview pre code { + border: none; + margin-left: 0; + padding-left: 0; + } -.wmd-preview p code { - border: none; - margin: 0; - padding: 0; -} + .wmd-preview p code { + border: none; + margin: 0; + padding: 0; + } .wmd-prompt-dialog { -border: solid 1px #ccc; -background-color: white; + border: solid 1px #ccc; + background-color: white; } /* Grippie */ div.grippie { - background:#EEEEEE url(../Content/Admin/Images/grippie.png) no-repeat scroll center 2px; - border-color:#DDDDDD; - border-style:solid; + background: #EEEEEE url(../Content/Admin/Images/grippie.png) no-repeat scroll center 2px; + border-color: #DDDDDD; + border-style: solid; border-width: 0 1px 1px; - cursor:s-resize; - height:9px; + cursor: s-resize; + height: 9px; margin-top: 9px; - overflow:hidden; + overflow: hidden; } + +.wmd-preview { + font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; + font-size: 14px; + line-height: 18px; + color: rgb(51, 51, 51); +} + + .wmd-preview h1 { + margin-bottom: 30px !important; + margin-top: 30px !important; + font-size: 30px !important; + } + + .wmd-preview h2 { + margin-bottom: 14px !important; + margin-top: 24px !important; + font-size: 24px !important; + font-weight: bold; + } + + .wmd-preview p { + line-height: 1.3em !important; + margin-bottom: 14px !important; + } + + .wmd-preview em { + font-style: italic !important; + } + + .wmd-preview ul { + margin-bottom: 14px !important; + } + + + .wmd-preview ul li { + margin-left: 10px !important; + } + +.wmd-preview code, .wmd-preview pre { + padding: 0 3px 2px !important; + font-family: Consolas,Monaco,"Courier New",monospace !important; + font-size: 12px !important; + color: #333333 !important; + line-height: 18px !important; + background-color: #f5f5f5 !important; + border: 1px solid #e1e1e8 !important; + border-radius: 3px !important; +} + +.wmd-preview code { + +} + +.wmd-preview pre { + display: block !important; + padding: 8.5px !important; + margin: 0 0 9px !important; + -webkit-border-radius: 4px !important; + -moz-border-radius: 4px !important; + border-radius: 4px !important; + white-space: pre !important; + -ms-word-break: break-all !important; + word-break: break-all !important; + -ms-word-wrap: break-word !important; + word-wrap: break-word !important; +} + +.wmd-preview pre code { + border: none !important; +} + +.wmd-preview dt{ + margin-left: 0 !important; + font-weight: bold !important; +} + +.wmd-preview dd { + margin-left: 10px !important; + +} \ No newline at end of file diff --git a/src/Orchard.Web/Modules/Markdown/Views/EditorTemplates/Parts/Markdown.MarkdownSiteSettings.cshtml b/src/Orchard.Web/Modules/Markdown/Views/EditorTemplates/Parts/Markdown.MarkdownSiteSettings.cshtml new file mode 100644 index 000000000..09b7bc268 --- /dev/null +++ b/src/Orchard.Web/Modules/Markdown/Views/EditorTemplates/Parts/Markdown.MarkdownSiteSettings.cshtml @@ -0,0 +1,10 @@ +@model Markdown.Models.MarkdownSiteSettingsPart + +
+ @T("Markdown") +
+ @Html.EditorFor(m => m.UseMarkdownForBlogs) + + @T("Enable to change the default editor for all blog posts to Markdown.") +
+
\ No newline at end of file