activityhtml

package module
v0.0.0-...-33b7355 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 22, 2025 License: MIT Imports: 12 Imported by: 0

README

go-activityhtml

Package activityhtml provides tools for working with ActivityHTML, for the Go programming language.

ActivityHTML is HTML that has ActivityPub / ActivityStream data marked-up or embedded into it using RDFa.

Documention

Online documentation, which includes examples, can be found at: http://godoc.org/codeberg.org/reiver/go-activityhtml

GoDoc

ActivityHTML

ActivityHTML is ActivityPub / ActivityStream encoded into HTML in a very specific way.

  • https://www.w3.org/ns/activitystreams#content — the HTML <main>
  • https://www.w3.org/ns/activitystreams#type — the value of the RDFa typeof attribute on the HTML <main>
  • https://www.w3.org/ns/activitystreams#attributedTo — the value of the href attribute on <a> with rel https://www.w3.org/ns/activitystreams#attributedTo inside of the HTML <main>

For example:

<main typeof="https://www.w3.org/ns/activitystreams#Note">
	<p>
		Hello world!
	</p>
</main>

That becomes:

{
	"@context": "https://www.w3.org/ns/activitystreams",
	type: "Note",
	content: "<main typeof=\"https://www.w3.org/ns/activitystreams#Note\">\n\t<p>\n\t\tHello world!\n\t</p></main>"
}

And, for example, this:

<main typeof="https://www.w3.org/ns/activitystreams#Note">
	<p>
		Hello world!
	</p>
	<footer>
		<address>
			<a rel="https://www.w3.org/ns/activitystreams#attributedTo" href="http://host.example/@dariush">@dariush@host.example</a>
		</address>
	</footer>
</main>

Becomes:

{
	"@context": "https://www.w3.org/ns/activitystreams",
	type: "Note",
	content: "<main typeof=\"https://www.w3.org/ns/activitystreams#Note\">\n\t<p>\n\t\tHello world!\n\t</p></main>",
	attributedTo: "http://host.example/@dariush"
}

Import

To import package activityhtml use import code like the following:

import "codeberg.org/reiver/go-activityhtml"

Installation

To install package activityhtml do the following:

GOPROXY=direct go get codeberg.org/reiver/go-activityhtml

Author

Package activityhtml was written by Charles Iliya Krempeaux

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExtractAttributedTo

func ExtractAttributedTo(str string) []string

func ExtractContent

func ExtractContent(str string) string

ExtractContent extracts the ActivityPub / ActivityStreams 'content' from the ActivityHTML.

ExtractContent expects the ActivityPub / ActivityStreams 'content' to be the <main> element. For example:

<main typeof="https://www.w3.org/ns/activitystreams#Note">
	<p>
		Hello world!
	</p>
</main>

In this example, the ActivityPub / ActivityStreams 'type' is:

`<main typeof="https://www.w3.org/ns/activitystreams#Note">
	<p>
		Hello world!
	</p>
</main>`

This assumes that there is only a single <main> element.

func ExtractTo

func ExtractTo(str string) []string

ExtractTo extracts the ActivityPub / ActivityStreams 'to' from the ActivityHTML.

Note that it currently is hard-coded to:

[]string{"https://www.w3.org/ns/activitystreams#Public"}

func ExtractType

func ExtractType(str string) []string

ExtractType extracts the ActivityPub / ActivityStreams 'type' from the ActivityHTML.

ExtractType expects the ActivityPub / ActivityStreams 'type' to be one the <main> element. For example:

<main typeof="https://www.w3.org/ns/activitystreams#Note">
	<p>
		Hello world!
	</p>
</main>

In this example, the ActivityPub / ActivityStreams 'type' is:

[]string{"https://www.w3.org/ns/activitystreams#Note"

Also, for example:

<main typeof="https://www.w3.org/ns/activitystreams#Note https://www.w3.org/ns/activitystreams#Article">
	<p>
		Hello world!
	</p>
</main>

In this example, the ActivityPub / ActivityStreams 'type' is:

[]string{
	"https://www.w3.org/ns/activitystreams#Note",
	"https://www.w3.org/ns/activitystreams#Article",
}

Types

type HTTPHandler

type HTTPHandler struct {
	SubHandler http.Handler
}

HTTPHandler is http.Handler middleware.

If the client has "application/activity+json" in their "Accept" request header, then will HTTPHandler r ActivityPub / ActivityStream ("application/activity+json") JSON data by transforming ActivityHTML into "application/activity+json".

func (HTTPHandler) ServeHTTP

func (receiver HTTPHandler) ServeHTTP(responseWriter http.ResponseWriter, request *http.Request)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL