Compare commits
13 Commits
5759251a03
...
49e1cc76ec
Author | SHA1 | Date |
---|---|---|
Aviad Ezra | 49e1cc76ec | |
Gary Ewan Park | 5ff6483ef7 | |
Travelmarx | f1fa3c9574 | |
Aviad Ezra | 9d2745af66 | |
Aviad Ezra | 896e349490 | |
Aviad Ezra | 3e04be6353 | |
Aviad Ezra | 590f16f71d | |
Aviad Ezra | c4fd8cdb2e | |
Aviad Ezra | a3f8426c85 | |
Aviad Ezra | 6ad9cf3b29 | |
Aviad Ezra | 1fd94f239d | |
Aviad Ezra | c3ae7e14d0 | |
Aviad Ezra | 9b7d7df306 |
|
@ -1,12 +1,12 @@
|
|||
# Open Live Writer
|
||||
Open Live Writer makes it easy to write, preview, and post to your blog.
|
||||
For more information see http://www.OpenLiveWriter.org/.
|
||||
For more information see http://www.OpenLiveWriter.com/.
|
||||
|
||||
[![Build status](https://ci.appveyor.com/api/projects/status/8xpga2y53sgwo24g?svg=true)](https://ci.appveyor.com/project/dotnetfoundation/openlivewriter)
|
||||
|
||||
### Installation
|
||||
You can install the latest version of Open Live Writer alongside an [older version of Windows Live Writer](http://windows.microsoft.com/en-us/windows-live/essentials). Visit
|
||||
http://www.OpenLiveWriter.org to download and install the latest release.
|
||||
http://www.OpenLiveWriter.com to download and install the latest release.
|
||||
|
||||
### Latest News
|
||||
The current version of Open Live Writer is our first open source version.
|
||||
|
@ -15,7 +15,7 @@ look at the [roadmap](roadmap.md) to see what the current plans are.
|
|||
|
||||
For the latest news and updates about Open Live Writer, you can follow us on Twitter
|
||||
([@OpenLiveWriter](https://twitter.com/OpenLiveWriter)), by keeping an eye on the website
|
||||
http://www.OpenLiveWriter.org or by watching this repo and subscribing to notifications.
|
||||
http://www.OpenLiveWriter.com or by watching this repo and subscribing to notifications.
|
||||
|
||||
### Contributing
|
||||
Open Live Writer is an open source project and wouldn't exist without the passionate community of volunteer
|
||||
|
|
|
@ -0,0 +1,86 @@
|
|||
using System;
|
||||
|
||||
namespace OpenLiveWriter.HtmlEditor
|
||||
{
|
||||
public class CodeHighlighter
|
||||
{
|
||||
private const int TAB_SIZE = 4;
|
||||
|
||||
private const string PRE_OPEN = "<pre>";
|
||||
private const string PRE_CLOSE = "</pre>";
|
||||
private const string PRE_OPEN_STYLED = "<pre class=\"prettyprint\">";
|
||||
private const string PRETTIFY_SCRIPT_NAME = "run_prettify.js";
|
||||
private const string DEFAULT_SKIN = CodeHighlighterSkins.Sunburst;
|
||||
|
||||
private static readonly string _prettifyScript =
|
||||
$"<script src=\"https://cdn.rawgit.com/google/code-prettify/master/loader/{PRETTIFY_SCRIPT_NAME}?skin={DEFAULT_SKIN}\"></script>";
|
||||
|
||||
public static string StyledHtml(string htmlText, string innerHtml)
|
||||
{
|
||||
// Using Google's prettifier (https://github.com/google/code-prettify)
|
||||
htmlText = SwapTabsForSpaces(htmlText);
|
||||
htmlText = ReplaceLineEndings(htmlText);
|
||||
htmlText = RemoveCode(htmlText, PRE_OPEN_STYLED, PRE_CLOSE);
|
||||
htmlText = RemoveCode(htmlText, PRE_OPEN, PRE_CLOSE);
|
||||
|
||||
bool addScript = ShouldAddJsScript(innerHtml);
|
||||
string script = addScript ? _prettifyScript : string.Empty;
|
||||
|
||||
string styledHtml = $"{script}{PRE_OPEN_STYLED}{htmlText}{PRE_CLOSE}";
|
||||
return styledHtml;
|
||||
}
|
||||
|
||||
private static string ReplaceLineEndings(string htmlText)
|
||||
{
|
||||
htmlText = htmlText.Replace(Environment.NewLine, "");
|
||||
return htmlText;
|
||||
}
|
||||
|
||||
private static string SwapTabsForSpaces(string text)
|
||||
{
|
||||
return text.Replace("\t", " ".PadLeft(TAB_SIZE));
|
||||
}
|
||||
|
||||
private static bool ShouldAddJsScript(string innerHtml)
|
||||
{
|
||||
var body = innerHtml.ToLowerInvariant();
|
||||
if (body.Contains(PRETTIFY_SCRIPT_NAME))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private static string RemoveCode(string htmlText, string open, string close)
|
||||
{
|
||||
string htmlL = htmlText.ToLowerInvariant();
|
||||
int index = htmlL.IndexOf(open, StringComparison.InvariantCulture);
|
||||
if (index >= 0)
|
||||
{
|
||||
htmlText = htmlText.Remove(index, open.Length);
|
||||
htmlL = htmlText.ToLowerInvariant();
|
||||
|
||||
index = htmlL.IndexOf(close, StringComparison.InvariantCulture);
|
||||
if (index >= 0)
|
||||
{
|
||||
htmlText = htmlText.Remove(index, close.Length);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return htmlText;
|
||||
}
|
||||
}
|
||||
|
||||
// To be used when adding support for skins
|
||||
// For example: https://cdn.rawgit.com/google/code-prettify/master/loader/run_prettify.js?skin=sunburst
|
||||
// All Styles: https://rawgit.com/google/code-prettify/master/styles/index.html
|
||||
public static class CodeHighlighterSkins
|
||||
{
|
||||
public const string Default = "default";
|
||||
public const string Sunburst = "sunburst";
|
||||
public const string SonsOfObsidian = "sons-of-obsidian";
|
||||
public const string Desert = "desert";
|
||||
}
|
||||
}
|
|
@ -4551,6 +4551,37 @@ namespace OpenLiveWriter.HtmlEditor
|
|||
ExecuteBlockCommand(new CommandExecutor(GetMshtmlCommand(IDM.OUTDENT).Execute));
|
||||
}
|
||||
|
||||
bool IHtmlEditorCommandSource.CanInsertCode
|
||||
{
|
||||
get
|
||||
{
|
||||
return Editable;
|
||||
}
|
||||
}
|
||||
|
||||
void IHtmlEditorCommandSource.InsertCode()
|
||||
{
|
||||
using (new WaitCursor())
|
||||
{
|
||||
var range = SelectedMarkupRange;
|
||||
string htmlText = range?.HtmlText;
|
||||
if (htmlText != null)
|
||||
{
|
||||
IUndoUnit undoUnit = CreateUndoUnit();
|
||||
using (undoUnit)
|
||||
{
|
||||
IHTMLDocument2 document = HTMLDocument;
|
||||
var styledHtml = CodeHighlighter.StyledHtml(htmlText, document.body.innerHTML);
|
||||
|
||||
InsertHtml(range.Start, range.End, styledHtml);
|
||||
|
||||
// commit the change
|
||||
undoUnit.Commit();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool IHtmlEditorCommandSource.CanInsertLink
|
||||
{
|
||||
get
|
||||
|
|
|
@ -613,6 +613,20 @@ namespace OpenLiveWriter.HtmlEditor
|
|||
// not supported
|
||||
}
|
||||
|
||||
bool IHtmlEditorCommandSource.CanInsertCode
|
||||
{
|
||||
get
|
||||
{
|
||||
// not suppported
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
void IHtmlEditorCommandSource.InsertCode()
|
||||
{
|
||||
// not supported
|
||||
}
|
||||
|
||||
bool IHtmlEditorCommandSource.CanInsertLink
|
||||
{
|
||||
get
|
||||
|
|
|
@ -71,6 +71,9 @@ namespace OpenLiveWriter.HtmlEditor
|
|||
void ApplyBlockquote();
|
||||
bool SelectionBlockquoted { get; }
|
||||
|
||||
bool CanInsertCode { get; }
|
||||
void InsertCode();
|
||||
|
||||
bool CanInsertLink { get; }
|
||||
void InsertLink();
|
||||
|
||||
|
|
|
@ -64,6 +64,7 @@
|
|||
<Compile Include="..\GlobalAssemblyInfo.cs" />
|
||||
<Compile Include="BasicHtmlGenerationService.cs" />
|
||||
<Compile Include="BoldApplier.cs" />
|
||||
<Compile Include="CodeHighlighter.cs" />
|
||||
<Compile Include="Controls\HtmlStylePicker.cs">
|
||||
<SubType>UserControl</SubType>
|
||||
</Compile>
|
||||
|
|
Binary file not shown.
After Width: | Height: | Size: 1.1 KiB |
Binary file not shown.
After Width: | Height: | Size: 628 B |
|
@ -158,6 +158,7 @@ namespace OpenLiveWriter.Localization
|
|||
ImageTilt = 1085,
|
||||
Indent = 1046,
|
||||
InsertClearBreak = 1039,
|
||||
InsertCode = 1041,
|
||||
InsertColumnLeft = 23377,
|
||||
InsertColumnRight = 23378,
|
||||
InsertEmoticon = 1102,
|
||||
|
|
|
@ -2110,6 +2110,26 @@ namespace OpenLiveWriter.Localization {
|
|||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized resource of type System.Drawing.Bitmap.
|
||||
/// </summary>
|
||||
public static System.Drawing.Bitmap InsertCode_LargeImage {
|
||||
get {
|
||||
object obj = ResourceManager.GetObject("InsertCode_LargeImage", resourceCulture);
|
||||
return ((System.Drawing.Bitmap)(obj));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized resource of type System.Drawing.Bitmap.
|
||||
/// </summary>
|
||||
public static System.Drawing.Bitmap InsertCode_SmallImage {
|
||||
get {
|
||||
object obj = ResourceManager.GetObject("InsertCode_SmallImage", resourceCulture);
|
||||
return ((System.Drawing.Bitmap)(obj));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized resource of type System.Drawing.Bitmap.
|
||||
/// </summary>
|
||||
|
|
|
@ -4986,4 +4986,10 @@
|
|||
<data name="VideoAspectRatioGroup_SmallImage" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||
<value>commandbitmaps\videostandardaspectratio_smallimage.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
|
||||
</data>
|
||||
<data name="InsertCode_LargeImage" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||
<value>CommandBitmaps\InsertCode.LargeImage.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
|
||||
</data>
|
||||
<data name="InsertCode_SmallImage" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||
<value>CommandBitmaps\InsertCode.SmallImage.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
|
||||
</data>
|
||||
</root>
|
|
@ -67,6 +67,8 @@
|
|||
<None Include="CommandBitmaps\AddTagProvider.LargeImage.png" />
|
||||
<None Include="CommandBitmaps\AddTagProvider.SmallImage.png" />
|
||||
<None Include="CommandBitmaps\AddWeblog.SmallImage.png" />
|
||||
<None Include="CommandBitmaps\InsertCode.LargeImage.png" />
|
||||
<None Include="CommandBitmaps\InsertCode.SmallImage.png" />
|
||||
<Content Include="CommandBitmaps\CustomSizeGallery_LargeImage.png" />
|
||||
<Content Include="CommandBitmaps\CustomSizeGallery_SmallImage.png" />
|
||||
<Content Include="CommandBitmaps\Effects_Black_and_White.png" />
|
||||
|
|
|
@ -1218,6 +1218,15 @@
|
|||
<data name="Command.InsertClearBreak.TooltipDescription" xml:space="preserve">
|
||||
<value>Insert a break after a picture to prevent text wrapping.</value>
|
||||
<comment>Button to insert a break after an aligned image to prevent text wrapping.</comment></data>
|
||||
<data name="Command.InsertCode.Keytip" xml:space="preserve">
|
||||
<value>IC</value>
|
||||
</data>
|
||||
<data name="Command.InsertCode.LabelTitle" xml:space="preserve">
|
||||
<value>Code</value>
|
||||
</data>
|
||||
<data name="Command.InsertCode.TooltipDescription" xml:space="preserve">
|
||||
<value>Transform to code with syntax highlighting.</value>
|
||||
</data>
|
||||
<data name="Command.InsertColumnLeft.Keytip" xml:space="preserve">
|
||||
<value>IL</value>
|
||||
</data>
|
||||
|
|
|
@ -3382,6 +3382,22 @@ namespace OpenLiveWriter.PostEditor
|
|||
_currentEditor.CommandSource.ApplyOutdent();
|
||||
}
|
||||
|
||||
public bool CanInsertCode
|
||||
{
|
||||
get
|
||||
{
|
||||
return CurrentEditingMode != EditingMode.PlainText
|
||||
&& !IsEditFieldSelected
|
||||
&& _currentEditor != null
|
||||
&& _currentEditor.CommandSource.CanInsertCode;
|
||||
}
|
||||
}
|
||||
|
||||
public void InsertCode()
|
||||
{
|
||||
_currentEditor.CommandSource.InsertCode();
|
||||
}
|
||||
|
||||
public bool CanInsertLink
|
||||
{
|
||||
get
|
||||
|
|
|
@ -603,6 +603,7 @@ namespace OpenLiveWriter.PostEditor
|
|||
InitializeCommand(new SuperscriptCommand());
|
||||
InitializeCommand(new SubscriptCommand());
|
||||
InitializeCommand(new ClearFormattingCommand());
|
||||
InitializeCommand(new InsertCodeCommand());
|
||||
|
||||
commandFontSize = new FontSizeCommand();
|
||||
CommandManager.Add(commandFontSize);
|
||||
|
@ -1418,6 +1419,21 @@ namespace OpenLiveWriter.PostEditor
|
|||
}
|
||||
}
|
||||
|
||||
private class InsertCodeCommand : TextEditingCommand
|
||||
{
|
||||
public override CommandId CommandId { get { return CommandId.InsertCode; } }
|
||||
|
||||
protected override void Execute()
|
||||
{
|
||||
PostEditor.InsertCode();
|
||||
}
|
||||
|
||||
public override void Manage()
|
||||
{
|
||||
Enabled = PostEditor.CanInsertCode;
|
||||
}
|
||||
}
|
||||
|
||||
private class InsertLinkCommand : TextEditingCommand
|
||||
{
|
||||
public override CommandId CommandId { get { return CommandId.InsertLink; } }
|
||||
|
|
|
@ -98,6 +98,9 @@
|
|||
<ItemGroup>
|
||||
<ResourceCompile Include="OpenLiveWriter.Ribbon.rc" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Xml Include="Ribbon.xml" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<Import Project="$(RepoRoot)\writer.build.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
|
|
|
@ -98,6 +98,7 @@
|
|||
<Command Name="cmdFormatImageSaveSettings" Keytip="DS" LabelTitle="Set to default" TooltipTitle="Set to default" TooltipDescription="Set the alignment, margin, picture style, and properties of this picture as the default for other pictures." Symbol="cmdFormatImageSaveSettings" Id="1100" Comment="ImageContextTabGroup-FormatImageTab-FormatImageSettingsGroup-FormatImageSaveSettings"/>
|
||||
<Command Name="cmdFormatImageRevertSettings" Keytip="DR" LabelTitle="Revert to original" TooltipTitle="Revert to original" TooltipDescription="Revert to the original version of this picture." Symbol="cmdFormatImageRevertSettings" Id="1101" Comment="ImageContextTabGroup-FormatImageTab-FormatImageSettingsGroup-FormatImageRevertSettings"/>
|
||||
<Command Name="cmdInsertEmoticon" LabelTitle="Emoticon" TooltipTitle="Emoticon" TooltipDescription="Insert an emoticon." Symbol="cmdInsertEmoticon" Id="1102" Comment="InsertTab-MediaGroup-InsertEmoticon"/>
|
||||
<Command Name="cmdInsertCode" LabelTitle="Code" TooltipTitle="Code" TooltipDescription="Insert code snippet." Symbol="cmdInsertCode" Id="1041" Comment="InsertTab-MediaGroup-InsertCode"/>
|
||||
<Command Name="cmdCustomSizeSmall" LabelTitle="&Small" TooltipTitle="Small" Symbol="cmdCustomSizeSmall" Id="1103" Comment="ImageContextTabGroup-FormatImageTab-FormatImageSizeGroup-CustomSizeGallery-CustomSizeSmall"/>
|
||||
<Command Name="cmdCustomSizeMedium" LabelTitle="&Medium" TooltipTitle="Medium" Symbol="cmdCustomSizeMedium" Id="1104" Comment="ImageContextTabGroup-FormatImageTab-FormatImageSizeGroup-CustomSizeGallery-CustomSizeMedium"/>
|
||||
<Command Name="cmdCustomSizeLarge" LabelTitle="&Large" TooltipTitle="Large" Symbol="cmdCustomSizeLarge" Id="1105" Comment="ImageContextTabGroup-FormatImageTab-FormatImageSizeGroup-CustomSizeGallery-CustomSizeLarge"/>
|
||||
|
@ -576,7 +577,7 @@
|
|||
<Group CommandName="cmdTablesGroup" SizeDefinition="OneButton" ApplicationModes="0">
|
||||
<Button CommandName="cmdInsertTable"/>
|
||||
</Group>
|
||||
<Group CommandName="cmdMediaGroup" SizeDefinition="SixButtons" ApplicationModes="0">
|
||||
<Group CommandName="cmdMediaGroup" SizeDefinition="SevenButtons" ApplicationModes="0">
|
||||
<Button CommandName="cmdInsertLink"/>
|
||||
<DropDownButton CommandName="cmdInsertImageSplit">
|
||||
<MenuGroup>
|
||||
|
@ -598,6 +599,7 @@
|
|||
<FlowMenuLayout Columns="10" Gripper="None"/>
|
||||
</DropDownGallery.MenuLayout>
|
||||
</DropDownGallery>
|
||||
<Button CommandName="cmdInsertCode"/>
|
||||
</Group>
|
||||
<Group CommandName="cmdPluginsGroup" SizeDefinition="TwoButtons" ApplicationModes="4">
|
||||
<!-- No plugins gallery if there are no installed plugins. -->
|
||||
|
|
Loading…
Reference in New Issue