Revert "Fix for escaping markdown characters in property descriptions (#12345)"
This reverts commit 4aa1597138.
This commit is contained in:
@@ -1,6 +1,4 @@
|
||||
using System.Globalization;
|
||||
using System.Text.RegularExpressions;
|
||||
using HeyRed.MarkdownSharp;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Umbraco.Cms.Core;
|
||||
using Umbraco.Cms.Core.Actions;
|
||||
@@ -307,51 +305,6 @@ internal class ContentMapDefinition : IMapDefinition
|
||||
{
|
||||
Properties = context.MapEnumerable<IProperty, ContentPropertyDto>(source.Properties).WhereNotNull()
|
||||
};
|
||||
var markdown = new Markdown();
|
||||
var linkCheck = new Regex("<a[^>]+>", RegexOptions.IgnoreCase);
|
||||
var evaluator = new MatchEvaluator(AddRelNoReferrer);
|
||||
foreach (TVariant variant in target.Variants)
|
||||
{
|
||||
foreach (Tab<ContentPropertyDisplay> tab in variant.Tabs)
|
||||
{
|
||||
if (tab.Properties == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
foreach (ContentPropertyDisplay property in tab.Properties)
|
||||
{
|
||||
if (string.IsNullOrEmpty(property.Description))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var description = markdown.Transform(property.Description);
|
||||
property.Description = linkCheck.Replace(description, evaluator);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private string AddRelNoReferrer(Match m)
|
||||
{
|
||||
string result = m.Value;
|
||||
if (!result.Contains("rel=", StringComparison.Ordinal))
|
||||
{
|
||||
result = result.Replace(">", " rel=\"noreferrer\">");
|
||||
}
|
||||
|
||||
if (!result.Contains("class=", StringComparison.Ordinal))
|
||||
{
|
||||
result = result.Replace(">", " class=\"underline\">");
|
||||
}
|
||||
|
||||
if (!result.Contains("target=", StringComparison.Ordinal))
|
||||
{
|
||||
result = result.Replace(">", " target=\"_blank\">");
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
// Umbraco.Code.MapAll -Segment -Language -DisplayName -AdditionalPreviewUrls
|
||||
@@ -408,7 +361,7 @@ internal class ContentMapDefinition : IMapDefinition
|
||||
{
|
||||
currentUser = currentIUserBackofficeUser;
|
||||
}
|
||||
else if (_backOfficeSecurityAccessor.BackOfficeSecurity?.CurrentUser is not null)
|
||||
else if(_backOfficeSecurityAccessor.BackOfficeSecurity?.CurrentUser is not null)
|
||||
{
|
||||
currentUser = _backOfficeSecurityAccessor.BackOfficeSecurity.CurrentUser;
|
||||
}
|
||||
|
||||
@@ -11,7 +11,6 @@
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Markdown" Version="2.2.1" />
|
||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
||||
<PackageReference Include="Serilog.AspNetCore" Version="7.0.0" />
|
||||
</ItemGroup>
|
||||
@@ -32,4 +31,4 @@
|
||||
<ItemGroup>
|
||||
<EmbeddedResource Include="EmbeddedResources\**\*" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
</Project>
|
||||
|
||||
@@ -4,96 +4,96 @@
|
||||
* @restrict E
|
||||
**/
|
||||
(function () {
|
||||
'use strict';
|
||||
'use strict';
|
||||
|
||||
angular
|
||||
.module("umbraco.directives")
|
||||
.component('umbProperty', {
|
||||
templateUrl: 'views/components/property/umb-property.html',
|
||||
controller: UmbPropertyController,
|
||||
controllerAs: 'vm',
|
||||
transclude: true,
|
||||
require: {
|
||||
parentUmbProperty: '?^^umbProperty',
|
||||
parentForm: '?^^form'
|
||||
},
|
||||
bindings: {
|
||||
property: "=",
|
||||
angular
|
||||
.module("umbraco.directives")
|
||||
.component('umbProperty', {
|
||||
templateUrl: 'views/components/property/umb-property.html',
|
||||
controller: UmbPropertyController,
|
||||
controllerAs: 'vm',
|
||||
transclude: true,
|
||||
require: {
|
||||
parentUmbProperty: '?^^umbProperty',
|
||||
parentForm: '?^^form'
|
||||
},
|
||||
bindings: {
|
||||
property: "=",
|
||||
node: "<",
|
||||
elementKey: "@",
|
||||
// optional, if set this will be used for the property alias validation path (hack required because NC changes the actual property.alias :/)
|
||||
propertyAlias: "@",
|
||||
showInherit: "<",
|
||||
elementKey: "@",
|
||||
// optional, if set this will be used for the property alias validation path (hack required because NC changes the actual property.alias :/)
|
||||
propertyAlias: "@",
|
||||
showInherit: "<",
|
||||
inheritsFrom: "<",
|
||||
hideLabel: "<?"
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
|
||||
function UmbPropertyController($scope, userService, serverValidationManager, udiService, angularHelper) {
|
||||
|
||||
const vm = this;
|
||||
|
||||
vm.$onInit = onInit;
|
||||
|
||||
vm.setDirty = function () {
|
||||
// NOTE: We need to use scope because we haven't changd it to vm.propertyForm in the html and that
|
||||
// might mean a breaking change.
|
||||
$scope.propertyForm.$setDirty();
|
||||
}
|
||||
|
||||
vm.setPropertyError = function (errorMsg) {
|
||||
vm.property.propertyErrorMessage = errorMsg;
|
||||
};
|
||||
|
||||
vm.propertyActions = [];
|
||||
vm.setPropertyActions = function (actions) {
|
||||
vm.propertyActions = actions;
|
||||
};
|
||||
|
||||
// returns the validation path for the property to be used as the validation key for server side validation logic
|
||||
vm.getValidationPath = function () {
|
||||
|
||||
var parentValidationPath = vm.parentUmbProperty ? vm.parentUmbProperty.getValidationPath() : null;
|
||||
var propAlias = vm.propertyAlias ? vm.propertyAlias : vm.property.alias;
|
||||
// the elementKey will be empty when this is not a nested property
|
||||
var valPath = vm.elementKey ? vm.elementKey + "/" + propAlias : propAlias;
|
||||
return serverValidationManager.createPropertyValidationKey(valPath, parentValidationPath);
|
||||
}
|
||||
|
||||
function onInit() {
|
||||
vm.controlLabelTitle = null;
|
||||
if (Umbraco.Sys.ServerVariables.isDebuggingEnabled) {
|
||||
userService.getCurrentUser().then(function (u) {
|
||||
if (u.allowedSections.indexOf("settings") !== -1 ? true : false) {
|
||||
vm.controlLabelTitle = vm.property.alias;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if (!vm.parentUmbProperty) {
|
||||
// not found, then fallback to searching the scope chain, this may be needed when DOM inheritance isn't maintained but scope
|
||||
// inheritance is (i.e.infinite editing)
|
||||
var found = angularHelper.traverseScopeChain($scope, s => s && s.vm && s.vm.constructor.name === "UmbPropertyController");
|
||||
vm.parentUmbProperty = found ? found.vm : null;
|
||||
}
|
||||
|
||||
|
||||
if (vm.property.description) {
|
||||
// split by lines containing only '--'
|
||||
var descriptionParts = vm.property.description.split(/^--$/gim);
|
||||
if (descriptionParts.length > 1) {
|
||||
// if more than one part, we have an extended description,
|
||||
// combine to one extended description, and remove leading linebreak
|
||||
vm.property.extendedDescription = descriptionParts.splice(1).join("--").substring(1);
|
||||
vm.property.extendedDescriptionVisible = false;
|
||||
function UmbPropertyController($scope, userService, serverValidationManager, udiService, angularHelper) {
|
||||
|
||||
// set propertydescription to first part, and remove trailing linebreak
|
||||
vm.property.description = descriptionParts[0].slice(0, -1);
|
||||
const vm = this;
|
||||
|
||||
vm.$onInit = onInit;
|
||||
|
||||
vm.setDirty = function () {
|
||||
// NOTE: We need to use scope because we haven't changd it to vm.propertyForm in the html and that
|
||||
// might mean a breaking change.
|
||||
$scope.propertyForm.$setDirty();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
vm.setPropertyError = function (errorMsg) {
|
||||
vm.property.propertyErrorMessage = errorMsg;
|
||||
};
|
||||
|
||||
vm.propertyActions = [];
|
||||
vm.setPropertyActions = function (actions) {
|
||||
vm.propertyActions = actions;
|
||||
};
|
||||
|
||||
// returns the validation path for the property to be used as the validation key for server side validation logic
|
||||
vm.getValidationPath = function () {
|
||||
|
||||
var parentValidationPath = vm.parentUmbProperty ? vm.parentUmbProperty.getValidationPath() : null;
|
||||
var propAlias = vm.propertyAlias ? vm.propertyAlias : vm.property.alias;
|
||||
// the elementKey will be empty when this is not a nested property
|
||||
var valPath = vm.elementKey ? vm.elementKey + "/" + propAlias : propAlias;
|
||||
return serverValidationManager.createPropertyValidationKey(valPath, parentValidationPath);
|
||||
}
|
||||
|
||||
function onInit() {
|
||||
vm.controlLabelTitle = null;
|
||||
if (Umbraco.Sys.ServerVariables.isDebuggingEnabled) {
|
||||
userService.getCurrentUser().then(function (u) {
|
||||
if (u.allowedSections.indexOf("settings") !== -1 ? true : false) {
|
||||
vm.controlLabelTitle = vm.property.alias;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if (!vm.parentUmbProperty) {
|
||||
// not found, then fallback to searching the scope chain, this may be needed when DOM inheritance isn't maintained but scope
|
||||
// inheritance is (i.e.infinite editing)
|
||||
var found = angularHelper.traverseScopeChain($scope, s => s && s.vm && s.vm.constructor.name === "UmbPropertyController");
|
||||
vm.parentUmbProperty = found ? found.vm : null;
|
||||
}
|
||||
|
||||
if (vm.property.description) {
|
||||
// split by lines containing only '--'
|
||||
var descriptionParts = vm.property.description.split(/^--$/gim);
|
||||
if (descriptionParts.length > 1) {
|
||||
// if more than one part, we have an extended description,
|
||||
// combine to one extended description, and remove leading linebreak
|
||||
vm.property.extendedDescription = descriptionParts.splice(1).join("--").substring(1);
|
||||
vm.property.extendedDescriptionVisible = false;
|
||||
|
||||
// set propertydescription to first part, and remove trailing linebreak
|
||||
vm.property.description = descriptionParts[0].slice(0, -1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
})();
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
/**
|
||||
* @ngdoc filter
|
||||
* @name umbraco.filters.simpleMarkdown
|
||||
* @description
|
||||
* Used when rendering a string as Markdown as HTML (i.e. with ng-bind-html). Allows use of **bold**, *italics*,  and [links](url)
|
||||
**/
|
||||
angular.module("umbraco.filters").filter('simpleMarkdown', function () {
|
||||
return function (text) {
|
||||
if (!text) {
|
||||
return '';
|
||||
}
|
||||
|
||||
return text
|
||||
.replace(/\*\*(.*)\*\*/gim, '<b>$1</b>')
|
||||
.replace(/\*(.*)\*/gim, '<i>$1</i>')
|
||||
.replace(/!\[(.*?)\]\((.*?)\)/gim, "<img alt='$1' src='$2' />")
|
||||
.replace(/\[(.*?)\]\((.*?)\)/gim, "<a href='$2' target='_blank' rel='noopener' class='underline'>$1</a>")
|
||||
.replace(/\n/g, '<br />').trim();
|
||||
};
|
||||
});
|
||||
@@ -0,0 +1,20 @@
|
||||
/**
|
||||
* @ngdoc filter
|
||||
* @name umbraco.filters.simpleMarkdown
|
||||
* @description
|
||||
* Used when rendering a string as Markdown as HTML (i.e. with ng-bind-html). Allows use of **bold**, *italics*,  and [links](url)
|
||||
**/
|
||||
angular.module("umbraco.filters").filter('simpleMarkdown', function () {
|
||||
return function (text) {
|
||||
if (!text) {
|
||||
return '';
|
||||
}
|
||||
|
||||
return text
|
||||
.replace(/\*\*(.*)\*\*/gim, '<b>$1</b>')
|
||||
.replace(/\*(.*)\*/gim, '<i>$1</i>')
|
||||
.replace(/!\[(.*?)\]\((.*?)\)/gim, "<img alt='$1' src='$2' />")
|
||||
.replace(/\[(.*?)\]\((.*?)\)/gim, "<a href='$2' target='_blank' class='underline'>$1</a>")
|
||||
.replace(/\n/g, '<br />').trim();
|
||||
};
|
||||
});
|
||||
@@ -13,12 +13,12 @@
|
||||
|
||||
<umb-property-actions actions="vm.propertyActions"></umb-property-actions>
|
||||
|
||||
<small class="control-description" ng-if="vm.property.description" ng-bind-html="vm.property.description"></small>
|
||||
<small class="control-description" ng-if="vm.property.description" ng-bind-html="vm.property.description | simpleMarkdown"></small>
|
||||
|
||||
<div ng-if="vm.property.extendedDescription">
|
||||
|
||||
<div ng-if="vm.property.extendedDescriptionVisible">
|
||||
<small class="control-description" ng-bind-html="vm.property.extendedDescription"></small>
|
||||
<small class="control-description" ng-bind-html="vm.property.extendedDescription | simpleMarkdown"></small>
|
||||
</div>
|
||||
|
||||
<button type="button" class="btn btn-mini btn-link btn-link-reverse p0" ng-click="vm.property.extendedDescriptionVisible = !vm.property.extendedDescriptionVisible">
|
||||
|
||||
Reference in New Issue
Block a user