Improving Markdown support

- Adding a settings page to enable Markdown on Blogs
- Improving live preview Markdown styles
This commit is contained in:
Sebastien Ros 2014-02-17 17:15:37 -08:00
parent dd52801aa9
commit 1f81355afd
6 changed files with 224 additions and 53 deletions

View File

@ -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<MarkdownSiteSettingsPart>("Site"));
Filters.Add(new TemplateFilterForPart<MarkdownSiteSettingsPart>("MarkdownSiteSettings", "Parts/Markdown.MarkdownSiteSettings", "markdown"));
OnInitializing<MarkdownSiteSettingsPart>((context, part) => {
part.UseMarkdownForBlogs = false;
});
OnUpdated<MarkdownSiteSettingsPart>((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")));
}
}
}

View File

@ -119,6 +119,9 @@
<Content Include="Views\Body-Markdown.Editor.cshtml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Handlers\MarkdownSiteSettingsPartHandler.cs" />
<Compile Include="Migrations.cs" />
<Compile Include="Models\MarkdownSiteSettingsPart.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="ResourceManifest.cs" />
<Compile Include="Services\MarkdownFilter.cs" />
@ -168,6 +171,9 @@
<DependentUpon>orchard-markdown.js</DependentUpon>
</Content>
</ItemGroup>
<ItemGroup>
<Content Include="Views\EditorTemplates\Parts\Markdown.MarkdownSiteSettings.cshtml" />
</ItemGroup>
<PropertyGroup>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>

View File

@ -0,0 +1,11 @@
using Orchard.ContentManagement.MetaData;
using Orchard.Data.Migration;
namespace Markdown {
public class Migrations : DataMigrationImpl {
public int Create() {
return 1;
}
}
}

View File

@ -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); }
}
}
}

View File

@ -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;
}

View File

@ -0,0 +1,10 @@
@model Markdown.Models.MarkdownSiteSettingsPart
<fieldset>
<legend>@T("Markdown")</legend>
<div>
@Html.EditorFor(m => m.UseMarkdownForBlogs)
<label class="forcheckbox" for="@Html.FieldIdFor(m => m.UseMarkdownForBlogs)">@T("Use Markdown to write Blog Post")</label>
<span class="hint">@T("Enable to change the default editor for all blog posts to Markdown.")</span>
</div>
</fieldset>