Skip to content

Commit

Permalink
Scripts can now have attributes.
Browse files Browse the repository at this point in the history
  • Loading branch information
RyanLamansky committed Aug 4, 2024
1 parent a8e8360 commit 21449b2
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions HtmlUtilities/HtmlWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -356,13 +356,23 @@ public void WriteText(ReadOnlySpan<char> text)
/// </summary>
/// <param name="script">The script element to write.</param>
public void WriteScript(ValidatedScript script)
=> WriteScript(null, script);

/// <summary>
/// Writes a pre-validated script element.
/// </summary>
/// <param name="attributes">If provided, writes attributes to the element.</param>
/// <param name="script">The script element to write.</param>
public void WriteScript(Action<AttributeWriter>? attributes, ValidatedScript script)
{
var value = script.value;
if (value.IsEmpty)
return;

writer.Write("<script"u8);
writer.Write(this.cspNonce.value);
if (attributes is not null)
attributes(new AttributeWriter(writer));
writer.Write(value);
writer.Write("</script>"u8);
}
Expand Down

0 comments on commit 21449b2

Please sign in to comment.