Compare commits

...

13 Commits

Author SHA1 Message Date
Aviad Ezra 49e1cc76ec
Merge 9d2745af66 into 5ff6483ef7 2024-01-19 21:47:00 -07:00
Gary Ewan Park 5ff6483ef7
Merge pull request #919 from travelmarx/patch-1
Update README.md to point to .com instead of .org
2024-01-14 10:52:37 +00:00
Travelmarx f1fa3c9574
Update README.md to point to .com instead of .org
This is what was already done on OpenLiveWriter.Github.io README.
2020-08-15 11:18:45 +02:00
Aviad Ezra 9d2745af66 Set default skin to Sunburst 2017-07-27 15:24:29 -07:00
Aviad Ezra 896e349490 Style fixes 2017-07-27 13:46:38 -07:00
Aviad Ezra 3e04be6353 Minor style changes 2017-07-26 15:28:58 -07:00
Aviad Ezra 590f16f71d Added prettyprint sctipt to HTML 2017-07-26 15:21:30 -07:00
Aviad Ezra c4fd8cdb2e Use google's code-prettify 2017-07-26 14:14:54 -07:00
Aviad Ezra a3f8426c85 Add html markup inital 2017-07-25 23:09:33 -07:00
Aviad Ezra 6ad9cf3b29 Add InsertCode implementation to the Editor class 2017-07-25 21:24:12 -07:00
Aviad Ezra 1fd94f239d Move InsertCode to dedicated command 2017-07-25 21:03:55 -07:00
Aviad Ezra c3ae7e14d0 Added InsertCode button to the Insert/Media tab 2017-07-25 20:26:20 -07:00
Aviad Ezra 9b7d7df306 Include Ribbon.xml in OpenLiveWriter.Ribbon.vcxproj 2017-07-25 20:24:46 -07:00
17 changed files with 214 additions and 4 deletions

View File

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

View File

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

View File

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

View File

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

View File

@ -71,6 +71,9 @@ namespace OpenLiveWriter.HtmlEditor
void ApplyBlockquote();
bool SelectionBlockquoted { get; }
bool CanInsertCode { get; }
void InsertCode();
bool CanInsertLink { get; }
void InsertLink();

View File

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

View File

@ -158,6 +158,7 @@ namespace OpenLiveWriter.Localization
ImageTilt = 1085,
Indent = 1046,
InsertClearBreak = 1039,
InsertCode = 1041,
InsertColumnLeft = 23377,
InsertColumnRight = 23378,
InsertEmoticon = 1102,

View File

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

View File

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

View File

@ -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" />

View File

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

View File

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

View File

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

View File

@ -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">

View File

@ -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="&amp;Small" TooltipTitle="Small" Symbol="cmdCustomSizeSmall" Id="1103" Comment="ImageContextTabGroup-FormatImageTab-FormatImageSizeGroup-CustomSizeGallery-CustomSizeSmall"/>
<Command Name="cmdCustomSizeMedium" LabelTitle="&amp;Medium" TooltipTitle="Medium" Symbol="cmdCustomSizeMedium" Id="1104" Comment="ImageContextTabGroup-FormatImageTab-FormatImageSizeGroup-CustomSizeGallery-CustomSizeMedium"/>
<Command Name="cmdCustomSizeLarge" LabelTitle="&amp;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. -->