Command line client for Write.as https://write.as/apps/cli
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

20 linhas
407 B

  1. package posts
  2. import (
  3. "strings"
  4. )
  5. func ExtractTitle(content string) (title string, body string) {
  6. if hashIndex := strings.Index(content, "# "); hashIndex == 0 {
  7. eol := strings.IndexRune(content, '\n')
  8. // First line should start with # and end with \n
  9. if eol != -1 {
  10. body = strings.TrimLeft(content[eol:], " \t\n\r")
  11. title = content[len("# "):eol]
  12. return
  13. }
  14. }
  15. body = content
  16. return
  17. }