pavelbannov
320a1f2250
# Conflicts: # common/ASC.Api.Core/Core/BaseStartup.cs # common/ASC.Common/Caching/AscCache.cs # common/ASC.Common/Data/StreamExtension.cs # common/ASC.Common/Utils/RandomString.cs # common/ASC.Core.Common/Billing/CouponManager.cs # common/ASC.Core.Common/Billing/License/LicenseReader.cs # common/ASC.Core.Common/Core/UserGroupRef.cs # common/ASC.Core.Common/Data/DbTenantService.cs # common/ASC.Core.Common/Notify/Jabber/JabberServiceClientWcf.cs # common/ASC.Core.Common/Notify/Telegram/Dao/CachedTelegramDao.cs # common/ASC.Data.Backup.Core/Core/DbHelper.cs # common/ASC.Data.Backup.Core/Storage/BackupRepository.cs # common/ASC.Data.Backup.Core/Tasks/Data/TableInfo.cs # common/ASC.Data.Storage/BaseStorage.cs # common/ASC.Data.Storage/DiscStorage/DiscDataStore.cs # common/ASC.Data.Storage/GoogleCloud/GoogleCloudStorage.cs # common/ASC.Data.Storage/RackspaceCloud/RackspaceCloudStorage.cs # common/ASC.Data.Storage/S3/S3Storage.cs # common/ASC.Notify.Textile/JabberStyler.cs # common/ASC.Textile/Blocks/GlyphBlockModifier.cs # common/ASC.Textile/States/TableRowFormatterState.cs # common/services/ASC.ApiSystem/Classes/CommonMethods.cs # common/services/ASC.ApiSystem/Controllers/PortalController.cs # common/services/ASC.ClearEvents/Program.cs # common/services/ASC.TelegramService/Startup.cs # common/services/ASC.UrlShortener.Svc/Program.cs # products/ASC.Files/Core/Core/Entries/File.cs # products/ASC.Files/Core/Core/Entries/FileEntry.cs # products/ASC.Files/Core/Core/Entries/FileHelper.cs # products/ASC.Files/Core/Core/Entries/Folder.cs # products/ASC.Files/Core/Core/FileStorageService.cs # products/ASC.Files/Core/Core/Thirdparty/ProviderDao/ProviderDaoBase.cs # products/ASC.Files/Core/Helpers/ThirdpartyConfiguration.cs # products/ASC.Files/Core/HttpHandlers/FileHandler.ashx.cs # products/ASC.Files/Core/Services/DocumentService/Configuration.cs # products/ASC.Files/Core/Services/DocumentService/DocumentServiceConnector.cs # products/ASC.Files/Core/Services/DocumentService/DocumentServiceTracker.cs # products/ASC.Files/Core/Services/WCFService/FileOperations/FileDownloadOperation.cs # products/ASC.Files/Core/Services/WCFService/FileOperations/FileMoveCopyOperation.cs # products/ASC.Files/Core/Utils/EntryManager.cs # products/ASC.Files/Server/Helpers/FilesControllerHelper.cs # products/ASC.Files/Server/Startup.cs # products/ASC.Files/Service/Thumbnail/Builder.cs # products/ASC.Files/Service/Thumbnail/FileDataProvider.cs # products/ASC.People/Server/Startup.cs # web/ASC.Web.Core/Files/DocumentService.cs # web/ASC.Web.Core/Files/DocumentServiceLicense.cs # web/ASC.Web.Core/QuotaSync.cs # web/ASC.Web.Core/Sms/SmsKeyStorage.cs # web/ASC.Web.Core/Users/UserManagerWrapper.cs # web/ASC.Web.HealthChecks.UI/Program.cs # web/ASC.Web.Studio/Startup.cs
89 lines
4.1 KiB
C#
89 lines
4.1 KiB
C#
#region License Statement
|
|
// Copyright (c) L.A.B.Soft. All rights reserved.
|
|
//
|
|
// The use and distribution terms for this software are covered by the
|
|
// Common Public License 1.0 (http://opensource.org/licenses/cpl.php)
|
|
// which can be found in the file CPL.TXT at the root of this distribution.
|
|
// By using this software in any fashion, you are agreeing to be bound by
|
|
// the terms of this license.
|
|
//
|
|
// You must not remove this notice, or any other, from this software.
|
|
#endregion
|
|
|
|
namespace Textile.Blocks
|
|
{
|
|
public class GlyphBlockModifier : BlockModifier
|
|
{
|
|
public override string ModifyLine(string line)
|
|
{
|
|
line = Regex.Replace(line, "\"\\z", "\" ");
|
|
|
|
// fix: hackish
|
|
string[,] glyphs = {
|
|
{ @"([^\s[{(>_*])?\'(?(1)|(\s|s\b|" + Globals.PunctuationPattern + @"))", "$1’$2" }, // single closing
|
|
{ @"\'", "‘" }, // single opening
|
|
{ @"([^\s[{(>_*])?""(?(1)|(\s|" + Globals.PunctuationPattern + @"))", "$1”$2" }, // double closing
|
|
{ @"""", "“" }, // double opening
|
|
{ @"\b( )?\.{3}", "$1…" }, // ellipsis
|
|
{ @"\b([A-Z][A-Z0-9]{2,})\b(?:[(]([^)]*)[)])", "<acronym title=\"$2\">$1</acronym>" }, // 3+ uppercase acronym
|
|
{ @"(\s)?--(\s)?", "$1—$2" }, // em dash
|
|
{ @"\s-\s", " – " }, // en dash
|
|
{ @"(\d+)( )?x( )?(\d+)", "$1$2×$3$4" }, // dimension sign
|
|
{ @"\b ?[([](TM|tm)[])]", "™" }, // trademark
|
|
{ @"\b ?[([](R|r)[])]", "®" }, // registered
|
|
{ @"\b ?[([](C|c)[])]", "©" } // copyright
|
|
};
|
|
|
|
var sb = new StringBuilder();
|
|
|
|
if (!Regex.IsMatch(line, "<.*>"))
|
|
{
|
|
// If no HTML, do a simple search & replace.
|
|
for (var i = 0; i < glyphs.GetLength(0); ++i)
|
|
{
|
|
line = Regex.Replace(line, glyphs[i, 0], glyphs[i, 1]);
|
|
}
|
|
sb.Append(line);
|
|
}
|
|
else
|
|
{
|
|
var splits = Regex.Split(line, "(<.*?>)");
|
|
var offtags = "code|pre|notextile";
|
|
var codepre = false;
|
|
|
|
foreach (var split in splits)
|
|
{
|
|
var modifiedSplit = split;
|
|
if (modifiedSplit.Length == 0)
|
|
continue;
|
|
|
|
if (Regex.IsMatch(modifiedSplit, @"<(" + offtags + ")>"))
|
|
codepre = true;
|
|
if (Regex.IsMatch(modifiedSplit, @"<\/(" + offtags + ")>"))
|
|
codepre = false;
|
|
|
|
if (!Regex.IsMatch(modifiedSplit, "<.*>") && !codepre)
|
|
{
|
|
for (var i = 0; i < glyphs.GetLength(0); ++i)
|
|
{
|
|
modifiedSplit = Regex.Replace(modifiedSplit, glyphs[i, 0], glyphs[i, 1]);
|
|
}
|
|
}
|
|
|
|
// do htmlspecial if between <code>
|
|
if (codepre)
|
|
{
|
|
//TODO: htmlspecialchars(line)
|
|
//line = Regex.Replace(line, @"<(\/?" + offtags + ")>", "<$1>");
|
|
//line = line.Replace("&#", "&#");
|
|
}
|
|
|
|
sb.Append(modifiedSplit);
|
|
}
|
|
}
|
|
|
|
return sb.ToString();
|
|
}
|
|
}
|
|
}
|