Page Menu
Home
Musing Studio
Search
Configure Global Search
Log In
Files
F10587935
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
1 KB
Subscribers
None
View Options
diff --git a/formatting.go b/formatting.go
new file mode 100644
index 0000000..5a85aee
--- /dev/null
+++ b/formatting.go
@@ -0,0 +1,39 @@
+package writeas
+
+import (
+ "fmt"
+ "net/http"
+)
+
+type BodyResponse struct {
+ Body string `json:"body"`
+}
+
+// Markdown takes raw Markdown and renders it into usable HTML. See
+// https://developers.write.as/docs/api/#render-markdown.
+func (c *Client) Markdown(body, collectionURL string) (string, error) {
+ p := &BodyResponse{}
+ data := struct {
+ RawBody string `json:"raw_body"`
+ CollectionURL string `json:"collection_url,omitempty"`
+ }{
+ RawBody: body,
+ CollectionURL: collectionURL,
+ }
+
+ env, err := c.post("/markdown", data, p)
+ if err != nil {
+ return "", err
+ }
+
+ var ok bool
+ if p, ok = env.Data.(*BodyResponse); !ok {
+ return "", fmt.Errorf("Wrong data returned from API.")
+ }
+ status := env.Code
+
+ if status != http.StatusOK {
+ return "", fmt.Errorf("Problem getting markdown: %d. %s\n", status, env.ErrorMessage)
+ }
+ return p.Body, nil
+}
diff --git a/formatting_test.go b/formatting_test.go
new file mode 100644
index 0000000..0a83844
--- /dev/null
+++ b/formatting_test.go
@@ -0,0 +1,23 @@
+package writeas
+
+import (
+ "testing"
+)
+
+func TestMarkdown(t *testing.T) {
+ dwac := NewDevClient()
+
+ in := "This is *formatted* in __Markdown__."
+ out := `<p>This is <em>formatted</em> in <strong>Markdown</strong>.</p>
+`
+
+ res, err := dwac.Markdown(in, "")
+ if err != nil {
+ t.Errorf("Unexpected fetch results: %+v, err: %v\n", res, err)
+ }
+
+ if res != out {
+ t.Errorf(`Got: '%s'
+Expected: '%s'`, res, out)
+ }
+}
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Fri, Apr 25, 12:06 AM (1 d, 10 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3214743
Attached To
rWGO writeas-go
Event Timeline
Log In to Comment