Vazor icon indicating copy to clipboard operation
Vazor copied to clipboard

HTML doctype not allowed

Open InteXX opened this issue 1 year ago • 10 comments

There doesn't seem to be a way to get around the problem of XElement not supporting XML DTDs, at least not for Vazor MVC projects.

This:

Return _
       _
<!DOCTYPE html>
<html>
  <head>
    <title>Some Page</title>
  </head>
  <body>
    <p>This is some page!</p>
  </body>
</html>

Results in this:

XML DTDs are not supported

There does exist a workaround for a Vazor Pages project:

' Index.cshtml.vb
Public ReadOnly Property ViewName As String
  Get
    Dim sHtml As String

    Me.ViewData("Title") = TITLE
    sHtml = $"<!DOCTYPE html>{vbCrLf}"
    sHtml &= Me.GetVbXml(Me.ViewData).ParseZML

    Return VazorPage.CreateNew("Index", "Pages", TITLE, sHtml)
  End Get
End Property

But with Vazor MVC, the GetVbXml() method is called internally. There doesn't appear to be a way to insert that HTML doctype. An XElement can't contain an XDocumentType.

I then thought for a brief moment to update the LayoutView.Content property after the base constructor is called, but that property is read-only.

Any ideas?

InteXX avatar Nov 27 '23 03:11 InteXX

Well shucks, that didn't take long...!

I didn't realize that you'd made the Content property Overridable. Good thinking!

Here's the final result (that works):

Imports System.Xml.Linq
Imports Microsoft.VisualBasic
Imports Vazor

Public Class LayoutView
  Inherits VazorSharedView

  Public Sub New()
    MyBase.New("_Layout", "Views\Shared", "Website")
  End Sub

  Public Overrides ReadOnly Property Content As Byte()
    Get
      With Me.Encoding
        Return .GetBytes($"{DTD}{vbCrLf}{ .GetString(MyBase.Content)}")
      End With
    End Get
  End Property

  Public Overrides Function GetVbXml() As XElement
    Return _
           _
    <html>
        ...
    </html>
  End Function
End Class

It's probably best to do something similar in a Vazor Pages project as well.

InteXX avatar Nov 27 '23 03:11 InteXX

Just use the z:doctype tag. As I said, ZML solves some XML literals problems, and this is why I combined it with vazor :

        Return _
 _
        <zml xmlns:z="zml">
            <z:doctype html=""/>

From: Jeff Bowman @.> Sent: Monday, November 27, 2023 3:29 AM To: VBAndCs/Vazor @.> Cc: Subscribed @.***> Subject: Re: [VBAndCs/Vazor] HTML doctype not allowed (Issue #16)

Well shucks, that didn't take long...!

I didn't realize that you'd made the Content property Overridable. Good thinking!

Here's the final result (that works):

Imports System.Xml.Linq Imports Microsoft.VisualBasic Imports Vazor

Public Class LayoutView Inherits VazorSharedView

Public Sub New() MyBase.New("_Layout", "Views\Shared", "Website") End Sub

Public Overrides ReadOnly Property Content As Byte() Get Dim sHtml As String

  sHtml = $"<!DOCTYPE html>{vbCrLf}"
  sHtml &= Me.Encoding.GetString(MyBase.Content)

  Return Me.Encoding.GetBytes(sHtml)
End Get

End Property

Public Overrides Function GetVbXml() As XElement Return _ _ ... End Function End Class

It's probably best to do it this way in a Vazor Pages project as well.

— Reply to this email directly, view it on GitHubhttps://github.com/VBAndCs/Vazor/issues/16#issuecomment-1827072225, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ALQ5MVTII5KOWM6IG7MEJD3YGQCJXAVCNFSM6AAAAAA73LSAYOVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTQMRXGA3TEMRSGU. You are receiving this because you are subscribed to this thread.

[https://s-install.avcdn.net/ipm/preview/icons/icon-envelope-tick-round-orange-animated-no-repeat-v1.gif]https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail Virus-free.www.avast.comhttps://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail

VBAndCs avatar Nov 27 '23 08:11 VBAndCs

And if you want more control, override thee content property as you did, and create a document and set its declaration:

    Public Overrides ReadOnly Property Content() As Byte()
        Get
            Dim html = GetVbXml()
            Dim doc = New XDocument(html)
            doc.Declaration = New XDeclaration("1.0", "utf-8", "true")
            Return Encoding.GetBytes(doc.ToString().ParseZML)
        End Get
    End Property

for more info: https://learn.microsoft.com/en-us/dotnet/api/system.xml.linq.xdocument.documenttype?view=net-8.0


From: Jeff Bowman @.> Sent: Monday, November 27, 2023 3:29 AM To: VBAndCs/Vazor @.> Cc: Subscribed @.***> Subject: Re: [VBAndCs/Vazor] HTML doctype not allowed (Issue #16)

Well shucks, that didn't take long...!

I didn't realize that you'd made the Content property Overridable. Good thinking!

Here's the final result (that works):

Imports System.Xml.Linq Imports Microsoft.VisualBasic Imports Vazor

Public Class LayoutView Inherits VazorSharedView

Public Sub New() MyBase.New("_Layout", "Views\Shared", "Website") End Sub

Public Overrides ReadOnly Property Content As Byte() Get Dim sHtml As String

  sHtml = $"<!DOCTYPE html>{vbCrLf}"
  sHtml &= Me.Encoding.GetString(MyBase.Content)

  Return Me.Encoding.GetBytes(sHtml)
End Get

End Property

Public Overrides Function GetVbXml() As XElement Return _ _ ... End Function End Class

It's probably best to do it this way in a Vazor Pages project as well.

— Reply to this email directly, view it on GitHubhttps://github.com/VBAndCs/Vazor/issues/16#issuecomment-1827072225, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ALQ5MVTII5KOWM6IG7MEJD3YGQCJXAVCNFSM6AAAAAA73LSAYOVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTQMRXGA3TEMRSGU. You are receiving this because you are subscribed to this thread.Message ID: @.***>

VBAndCs avatar Nov 27 '23 08:11 VBAndCs

Looks good!

You need to get your account back.

InteXX avatar Nov 27 '23 08:11 InteXX

FYI I couldn't get the second one to work as is. I tuned it just a bit:

Public Overrides ReadOnly Property Content As Byte()
  Get
    Dim oType As XDocumentType
    Dim oDoc As XDocument

    oType = New XDocumentType("html", Nothing, Nothing, Nothing)
    oDoc = New XDocument(Me.GetVbXml)
    oDoc.AddFirst(oType)

    Return Me.Encoding.GetBytes(oDoc.ToString)
  End Get
End Property

We need an HTML Doctype here instead of an XML Declaration.

I like this. It's cleaner than the string concatenation.

InteXX avatar Nov 27 '23 09:11 InteXX

p.s. It looks like they beat you to the ZML acronym by about four months 😉

https://gitlab.com/zeromage/zml-py/-/commits/develop

InteXX avatar Nov 27 '23 09:11 InteXX

Just use the z:doctype tag

I see in the comments in the default *.vbxml.vb files from the template something about installing a .VSIX package in order to get HTML code completion. I haven't installed such a package, though, and I do get code completion—at least for the HTML between the opening and closing <zml /> tags.

But we don't, on the other hand, get code completion for <z:* /> tags.

Could this be what you're referring to here?

InteXX avatar Nov 27 '23 23:11 InteXX

The auto completion provider is installed with the vazor templates. That note was before Vazor 2.0. I didn't provide auto-completion for ZML, because I got busy in other things. The auto-completion uses the two files installed on the user documents folder: commonHTML5Types.xsd and html_5.xsd. ZML tags and attributes should be added to those files.


From: Jeff Bowman @.> Sent: Monday, November 27, 2023 11:43 PM To: VBAndCs/Vazor @.> Cc: Mohammad Hamdy Ghanem @.>; Comment @.> Subject: Re: [VBAndCs/Vazor] HTML doctype not allowed (Issue #16)

Just use the z:doctype tag

I see in the comments in the default *.vbxml.vb files from the template something about installing a .VSIX package in order to get HTML code completion. I haven't installed such a package, though, and I do get code completion—at least for the HTML between the opening and closing tags.

But we don't, on the other hand, get code completion for <z:* /> tags.

Could this be what you're referring to here?

— Reply to this email directly, view it on GitHubhttps://github.com/VBAndCs/Vazor/issues/16#issuecomment-1828814083, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ALQ5MVR5RSJLK3KH6MVS473YGUQRRAVCNFSM6AAAAAA73LSAYOVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTQMRYHAYTIMBYGM. You are receiving this because you commented.Message ID: @.***>

VBAndCs avatar Nov 28 '23 00:11 VBAndCs

ZML tags are explained in the readme of the ZML repo. Using ZML allows you to design ASP.NET pages without using any VB or C# codes, instead using ZML tags (something like tag helpers).


From: Jeff Bowman @.> Sent: Monday, November 27, 2023 11:43 PM To: VBAndCs/Vazor @.> Cc: Mohammad Hamdy Ghanem @.>; Comment @.> Subject: Re: [VBAndCs/Vazor] HTML doctype not allowed (Issue #16)

Just use the z:doctype tag

I see in the comments in the default *.vbxml.vb files from the template something about installing a .VSIX package in order to get HTML code completion. I haven't installed such a package, though, and I do get code completion—at least for the HTML between the opening and closing tags.

But we don't, on the other hand, get code completion for <z:* /> tags.

Could this be what you're referring to here?

— Reply to this email directly, view it on GitHubhttps://github.com/VBAndCs/Vazor/issues/16#issuecomment-1828814083, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ALQ5MVR5RSJLK3KH6MVS473YGUQRRAVCNFSM6AAAAAA73LSAYOVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTQMRYHAYTIMBYGM. You are receiving this because you commented.Message ID: @.***>

VBAndCs avatar Nov 28 '23 01:11 VBAndCs

You need to get your account back.

The VB.NET community needs you.

InteXX avatar Nov 28 '23 01:11 InteXX