-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
- Loading branch information
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
# Markdown editor in Elm by GitHub Copilot | ||
|
||
I have done this almost solely by chatting with GitHub Copilot. | ||
|
||
Demo is here: [https://elm-vite-test.vercel.app/](https://elm-vite-test.vercel.app/) | ||
|
||
## Starting point | ||
|
||
I started by from a template for Vite and Elm https://github.com/lindsaykwardell/vite-elm-template. | ||
|
||
## Initial prompt | ||
|
||
The initial prompt was as follows: | ||
|
||
``` | ||
Create a basic markdown editor in Elm with the following features: | ||
* Create model for markdown with default text "type markdown here" | ||
* A text area where users can write markdown | ||
* Show a live preview of the markdown text as I type | ||
* Support for basic markdown syntax like headers, bold, italics | ||
* The markdown text and resulting HTML should be saved in the model. | ||
``` | ||
|
||
## Further conversation | ||
|
||
The conversation was then about which Elm package I needed to install and how to use VSCode, which I was slightly rusty | ||
at. | ||
|
||
I asked for more features once I had tried the initial version. Copilot wrote code to interact with JavaScript to access | ||
local storage. | ||
Something I've done many times but still Copilot was easier to use. | ||
|
||
At one point I asked for a slightly different style in the code when it comes to update and side effects. No problem | ||
there to get a changed version. | ||
|
||
Of course, I also got help with the CSS. | ||
|
||
## Deployment | ||
|
||
I knew already how to deploy to Vercel. So that was a matter of connecting the repository to my Vercel account. Vercel | ||
has support for Vite. | ||
|
||
## Conclusion | ||
|
||
GitHub Copilot did the job well, as expected, even in Elm, a language not so widespread as JavaScript. | ||
|
||
An interesting effect on my own thinking was that I started to think more about what I wanted and not how it should be | ||
accomplished. |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,93 @@ | ||
module Main exposing (main) | ||
port module Main exposing (Model, Msg, main) | ||
|
||
import Browser | ||
import HelloWorld exposing (helloWorld) | ||
import Html exposing (Html, div, img) | ||
import Html.Attributes exposing (src, style) | ||
import Msg exposing (Msg(..)) | ||
import VitePluginHelper | ||
import Html exposing (Html, button, div, h1, img, p, text, textarea) | ||
import Html.Attributes exposing (class, height, src, style, value) | ||
import Html.Events exposing (onClick, onInput) | ||
import Markdown | ||
import Time | ||
import VitePluginHelper exposing (asset) | ||
|
||
|
||
main : Program () Int Msg | ||
main = | ||
Browser.sandbox { init = 0, update = update, view = view } | ||
type alias Model = | ||
{ markdown : String | ||
, html : Html Msg | ||
} | ||
|
||
|
||
init : String -> ( Model, Cmd Msg ) | ||
init savedMarkdown = | ||
let | ||
markdown : String | ||
markdown = | ||
if savedMarkdown == "" then | ||
"type markdown here" | ||
|
||
else | ||
savedMarkdown | ||
in | ||
( { markdown = markdown | ||
, html = Markdown.toHtml [] markdown | ||
} | ||
, Cmd.none | ||
) | ||
|
||
|
||
update : Msg -> number -> number | ||
type Msg | ||
= MarkdownChanged String | ||
| DownloadMarkdown | ||
| Tick | ||
|
||
|
||
update : Msg -> Model -> ( Model, Cmd Msg ) | ||
update msg model = | ||
case msg of | ||
Increment -> | ||
model + 1 | ||
MarkdownChanged newMarkdown -> | ||
( { model | markdown = newMarkdown, html = Markdown.toHtml [] newMarkdown }, Cmd.none ) | ||
|
||
Decrement -> | ||
model - 1 | ||
DownloadMarkdown -> | ||
( model, downloadMarkdown model.markdown ) | ||
|
||
Tick -> | ||
( model, saveMarkdown model.markdown ) | ||
|
||
view : Int -> Html Msg | ||
|
||
view : Model -> Html Msg | ||
view model = | ||
div [] | ||
[ img [ src <| VitePluginHelper.asset "/src/assets/logotype.png", style "width" "300px" ] [] | ||
, helloWorld model | ||
[ img [ src <| asset "/src/assets/logotype.png", height 50 ] [] | ||
, h1 [] [ text "Markdown Editor" ] | ||
, p [] [ text "This is a simple markdown editor. It will save your markdown every 30 seconds locally in your browser. You can download the markdown by pressing the download button." ] | ||
, div [] | ||
[ textarea | ||
[ style "width" "100%" | ||
, style "height" "50vh" | ||
, value model.markdown | ||
, onInput MarkdownChanged | ||
] | ||
[] | ||
, button [ onClick DownloadMarkdown ] [ text "Download Markdown" ] | ||
, div [ class "markdown-output" ] [ model.html ] | ||
] | ||
] | ||
|
||
|
||
port downloadMarkdown : String -> Cmd msg | ||
|
||
|
||
port saveMarkdown : String -> Cmd msg | ||
|
||
|
||
subscriptions : Model -> Sub Msg | ||
subscriptions _ = | ||
Time.every 30000 (\_ -> Tick) | ||
|
||
|
||
main : Program String Model Msg | ||
main = | ||
Browser.element | ||
{ init = init | ||
, update = update | ||
, view = view | ||
, subscriptions = subscriptions | ||
} |
This file was deleted.