Skip to content

Commit

Permalink
New tag replacer that should be more reliable. More elegant too.
Browse files Browse the repository at this point in the history
  • Loading branch information
markdomansky committed Jun 20, 2022
1 parent a716a34 commit fe9fe6e
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 64 deletions.
6 changes: 3 additions & 3 deletions WebJEA/My Project/AssemblyInfo.vb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Imports System
Imports System
Imports System.Reflection
Imports System.Runtime.InteropServices

Expand All @@ -11,7 +11,7 @@ Imports System.Runtime.InteropServices
<Assembly: AssemblyDescription("webjea.com")>
<Assembly: AssemblyCompany("Mark Domansky")>
<Assembly: AssemblyProduct("WebJEA")>
<Assembly: AssemblyCopyright("Copyright © Mark Domansky, 2021")>
<Assembly: AssemblyCopyright("Copyright © Mark Domansky, 2021")>
<Assembly: AssemblyTrademark("")>

<Assembly: ComVisible(False)>
Expand All @@ -30,4 +30,4 @@ Imports System.Runtime.InteropServices
' by using the '*' as shown below:

' <Assembly: AssemblyFileVersion("1.1.0.0")>
<Assembly: AssemblyVersion("1.1.21213.21284")>
<Assembly: AssemblyVersion("1.1.22170.37840")>
55 changes: 13 additions & 42 deletions WebJEA/PSWebHelper.vb
Original file line number Diff line number Diff line change
Expand Up @@ -55,48 +55,19 @@
Return output
End Function

Private Function EncodeOutputTags(input As String) As String
Dim output As String = input
Dim IDX As Integer = output.IndexOf("[[")
While IDX > -1
Dim tagOpen As Integer = IDX
Dim tagSplit1 As Integer = output.IndexOf("|", tagOpen)
Dim tagSplit2 As Integer = output.IndexOf("|", tagSplit1 + 1)
Dim tagClose As Integer = output.LastIndexOf("]]", output.Length)

If tagSplit1 = -1 Then Return output 'bad format
If tagSplit2 = -1 Then Return output
If tagClose = -1 Then Return output

Dim tagType As String = output.Substring(tagOpen + 2, tagSplit1 - tagOpen - 2)
Dim tagContent1 As String = output.Substring(tagSplit1 + 1, tagSplit2 - tagSplit1 - 1)
Dim tagContent2 As String = output.Substring(tagSplit2 + 1, tagClose - tagSplit2 - 1)
Dim tagFull As String = output.Substring(tagOpen, tagClose - tagOpen + 2)

Dim tag As String = output.Substring(tagOpen, tagSplit1 - tagOpen + 1)
If tag.ToLower = "[[a|" Then
'link
tagContent1 = HttpContext.Current.Server.HtmlDecode(tagContent1)
Dim tagOutput = "<a class='pslink' href='" & tagContent1 & "'>" & tagContent2 & "</a>"
output = output.Replace(tagFull, tagOutput)

ElseIf tag.ToLower = "[[span|" Then
'span
Dim tagOutput = "<span class='" & tagContent1 & "'>" & tagContent2 & "</span>"
output = output.Replace(tagFull, tagOutput)

ElseIf tag.ToLower = "[[img|" Then
'span
tagContent2 = HttpContext.Current.Server.HtmlDecode(tagContent2)
Dim tagOutput = "<img class='" & tagContent1 & "' src='" & tagContent2 & "' />"
output = output.Replace(tagFull, tagOutput)

End If

IDX = output.IndexOf("[[", IDX + 1)
End While

Return output
Private Function EncodeOutputTags(ByVal input As String) As String
Dim rexopt As RegexOptions = RegexOptions.IgnoreCase + RegexOptions.Multiline
Const rexA As String = "\[\[a\|(.+?)\|(.+)\]\]"
Const repA As String = "<a href='$1'>$2</a>"
Const rexSpan As String = "\[\[span\|(.+?)\|(.+)\]\]"
Const repSpan As String = "<span Class='$1'>$2</span>"
Const rexImg As String = "\[\[img\|(.*?)\|(.+)\]\]"
Const repImg As String = "<img class='$1' src='$2' />"
input = Regex.Replace(input, rexA, repA, rexopt)
input = Regex.Replace(input, rexSpan, repSpan, rexopt)
input = Regex.Replace(input, rexImg, repImg, rexopt)

Return input
End Function


Expand Down
84 changes: 65 additions & 19 deletions WebJEA/WebJEA.vbproj
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
<UseGlobalApplicationHostFile />
<NuGetPackageImportStamp>
</NuGetPackageImportStamp>
<TypeScriptToolsVersion>4.2</TypeScriptToolsVersion>
<TypeScriptToolsVersion>4.3</TypeScriptToolsVersion>
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
Expand All @@ -36,6 +36,19 @@
<OutputPath>bin\</OutputPath>
<DocumentationFile>WebJEA.xml</DocumentationFile>
<NoWarn>42016,41999,42017,42018,42019,42032,42036,42020,42021,42022</NoWarn>
<TypeScriptTarget>ES5</TypeScriptTarget>
<TypeScriptJSXEmit>React</TypeScriptJSXEmit>
<TypeScriptModuleKind />
<TypeScriptCompileOnSaveEnabled>True</TypeScriptCompileOnSaveEnabled>
<TypeScriptNoImplicitAny>False</TypeScriptNoImplicitAny>
<TypeScriptRemoveComments>False</TypeScriptRemoveComments>
<TypeScriptOutFile />
<TypeScriptOutDir />
<TypeScriptGeneratesDeclarations>False</TypeScriptGeneratesDeclarations>
<TypeScriptNoEmitOnError>True</TypeScriptNoEmitOnError>
<TypeScriptSourceMap>True</TypeScriptSourceMap>
<TypeScriptMapRoot />
<TypeScriptSourceRoot />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
Expand Down Expand Up @@ -130,6 +143,7 @@
<Content Include="Content\bootstrap.min.css" />
<Content Include="Content\jquery-ui-timepicker-addon.css" />
<Content Include="Content\jquery-ui-timepicker-addon.min.css" />
<Content Include="Content\ps.png" />
<Content Include="Content\themes\base\accordion.css" />
<Content Include="Content\themes\base\all.css" />
<Content Include="Content\themes\base\autocomplete.css" />
Expand Down Expand Up @@ -174,9 +188,15 @@
<Content Include="default.aspx" />
<Content Include="error.aspx" />
<Content Include="Global.asax" />
<Content Include="loader.svg" />
<Content Include="main.css" />
<Content Include="psoutput.css" />
<Content Include="loader.svg">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="main.css">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="psoutput.css">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="Scripts\bootstrap.bundle.js" />
<Content Include="Scripts\bootstrap.bundle.min.js" />
<Content Include="Scripts\bootstrap.js" />
Expand Down Expand Up @@ -246,6 +266,8 @@
<Content Include="Scripts\bootstrap.js.map" />
<Content Include="Scripts\bootstrap.bundle.min.js.map" />
<Content Include="Scripts\bootstrap.bundle.js.map" />
<None Include="My Project\PublishProfiles\ReleaseBuild.pubxml" />
<None Include="My Project\PublishProfiles\Web22Dbg.pubxml" />
<None Include="NLog.xsd">
<SubType>Designer</SubType>
</None>
Expand Down Expand Up @@ -326,13 +348,27 @@
<Content Include="Scripts\src\utils\setAttributes.js" />
<Content Include="Scripts\src\utils\setStyles.js" />
<Content Include="Scripts\src\utils\setupEventListeners.js" />
<Content Include="Scripts\umd\popper-utils.js" />
<Content Include="Scripts\umd\popper-utils.min.js" />
<Content Include="Scripts\umd\popper.js" />
<Content Include="Scripts\umd\popper.min.js" />
<Content Include="sidebar.css" />
<Content Include="startup.js" />
<Content Include="validation.js" />
<Content Include="Scripts\umd\popper-utils.js">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="Scripts\umd\popper-utils.min.js">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="Scripts\umd\popper.js">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="Scripts\umd\popper.min.js">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="sidebar.css">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="startup.js">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="validation.js">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<None Include="Web.config" />
</ItemGroup>
<ItemGroup>
Expand Down Expand Up @@ -407,11 +443,21 @@
</None>
<None Include="NLog.config" />
<None Include="packages.config" />
<Content Include="Scripts\umd\popper.min.js.map" />
<Content Include="Scripts\umd\popper.js.map" />
<Content Include="Scripts\umd\popper.js.flow" />
<Content Include="Scripts\umd\popper-utils.min.js.map" />
<Content Include="Scripts\umd\popper-utils.js.map" />
<Content Include="Scripts\umd\popper.min.js.map">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="Scripts\umd\popper.js.map">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="Scripts\umd\popper.js.flow">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="Scripts\umd\popper-utils.min.js.map">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="Scripts\umd\popper-utils.js.map">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="Scripts\README.md" />
<Content Include="Scripts\popper.min.js.map" />
<Content Include="Scripts\popper.js.map" />
Expand Down Expand Up @@ -456,13 +502,13 @@
<VisualStudio>
<FlavorProperties GUID="{349c5851-65df-11da-9384-00065b846f21}">
<WebProjectProperties>
<UseIIS>False</UseIIS>
<UseIIS>True</UseIIS>
<AutoAssignPort>True</AutoAssignPort>
<DevelopmentServerPort>49851</DevelopmentServerPort>
<DevelopmentServerVPath>/</DevelopmentServerVPath>
<IISUrl>https://localhost:44334/</IISUrl>
<IISUrl>http://localhost:49851/</IISUrl>
<NTLMAuthentication>False</NTLMAuthentication>
<UseCustomServer>True</UseCustomServer>
<UseCustomServer>False</UseCustomServer>
<CustomServerUrl>https://web22dbg.domain1.local</CustomServerUrl>
<SaveServerSettingsInUserFile>False</SaveServerSettingsInUserFile>
</WebProjectProperties>
Expand Down

0 comments on commit fe9fe6e

Please sign in to comment.