sync: automatically add before ponctuation
This commit is contained in:
parent
0075bdeb52
commit
0d8505131e
@ -28,6 +28,8 @@ func SyncExerciceHints(i Importer, exercice fic.Exercice) (errs []string) {
|
|||||||
for n, hint := range params.Hints {
|
for n, hint := range params.Hints {
|
||||||
if hint.Title != "" {
|
if hint.Title != "" {
|
||||||
hint.Title = fmt.Sprintf("Astuce #%d", n+1)
|
hint.Title = fmt.Sprintf("Astuce #%d", n+1)
|
||||||
|
} else {
|
||||||
|
hint.Title = fixnbsp(hint.Title)
|
||||||
}
|
}
|
||||||
if hint.Cost <= 0 {
|
if hint.Cost <= 0 {
|
||||||
hint.Cost = exercice.Gain / 4
|
hint.Cost = exercice.Gain / 4
|
||||||
@ -72,7 +74,7 @@ func SyncExerciceHints(i Importer, exercice fic.Exercice) (errs []string) {
|
|||||||
} else if hint.Content == "" {
|
} else if hint.Content == "" {
|
||||||
errs = append(errs, fmt.Sprintf("%q: challenge.txt: hint %s (%d): content and filename can't be empty at the same time", path.Base(exercice.Path), hint.Title, n+1))
|
errs = append(errs, fmt.Sprintf("%q: challenge.txt: hint %s (%d): content and filename can't be empty at the same time", path.Base(exercice.Path), hint.Title, n+1))
|
||||||
continue
|
continue
|
||||||
} else if hint.Content, err = ProcessMarkdown(i, hint.Content, exercice.Path); err != nil{
|
} else if hint.Content, err = ProcessMarkdown(i, fixnbsp(hint.Content), exercice.Path); err != nil{
|
||||||
errs = append(errs, fmt.Sprintf("%q: challenge.txt: hint %s (%d): error during markdown formating: %s", path.Base(exercice.Path), hint.Title, n+1, err))
|
errs = append(errs, fmt.Sprintf("%q: challenge.txt: hint %s (%d): error during markdown formating: %s", path.Base(exercice.Path), hint.Title, n+1, err))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -11,6 +11,10 @@ import (
|
|||||||
"gopkg.in/russross/blackfriday.v2"
|
"gopkg.in/russross/blackfriday.v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func fixnbsp(s string) string {
|
||||||
|
return strings.Replace(strings.Replace(strings.Replace(s, " ?", " ?", -1), " !", " !", -1), " :", " :", -1)
|
||||||
|
}
|
||||||
|
|
||||||
// getExercices returns all exercice directories existing in a given theme, considering the given Importer.
|
// getExercices returns all exercice directories existing in a given theme, considering the given Importer.
|
||||||
func getExercices(i Importer, theme fic.Theme) ([]string, error) {
|
func getExercices(i Importer, theme fic.Theme) ([]string, error) {
|
||||||
var exercices []string
|
var exercices []string
|
||||||
@ -90,12 +94,14 @@ func SyncExercice(i Importer, theme fic.Theme, epath string, dmap *map[int64]fic
|
|||||||
}
|
}
|
||||||
|
|
||||||
e.URLId = fic.ToURLid(e.Title)
|
e.URLId = fic.ToURLid(e.Title)
|
||||||
|
e.Title = fixnbsp(e.Title)
|
||||||
|
|
||||||
// Texts to format using Markdown
|
// Texts to format using Markdown
|
||||||
e.Overview, err = getFileContent(i, path.Join(epath, "overview.txt"))
|
e.Overview, err = getFileContent(i, path.Join(epath, "overview.txt"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
errs = append(errs, fmt.Sprintf("%q: overview.txt: %s", edir, err))
|
errs = append(errs, fmt.Sprintf("%q: overview.txt: %s", edir, err))
|
||||||
} else {
|
} else {
|
||||||
|
e.Overview = fixnbsp(e.Overview)
|
||||||
e.Headline = string(blackfriday.Run([]byte(strings.Split(e.Overview, "\n")[0])))
|
e.Headline = string(blackfriday.Run([]byte(strings.Split(e.Overview, "\n")[0])))
|
||||||
if e.Overview, err = ProcessMarkdown(i, e.Overview, epath); err != nil {
|
if e.Overview, err = ProcessMarkdown(i, e.Overview, epath); err != nil {
|
||||||
errs = append(errs, fmt.Sprintf("%q: overview.txt: an error occurs during markdown formating: %s", edir, err))
|
errs = append(errs, fmt.Sprintf("%q: overview.txt: an error occurs during markdown formating: %s", edir, err))
|
||||||
@ -106,7 +112,7 @@ func SyncExercice(i Importer, theme fic.Theme, epath string, dmap *map[int64]fic
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
errs = append(errs, fmt.Sprintf("%q: statement.txt: %s", edir, err))
|
errs = append(errs, fmt.Sprintf("%q: statement.txt: %s", edir, err))
|
||||||
} else {
|
} else {
|
||||||
if e.Statement, err = ProcessMarkdown(i, e.Statement, epath); err != nil {
|
if e.Statement, err = ProcessMarkdown(i, fixnbsp(e.Statement), epath); err != nil {
|
||||||
errs = append(errs, fmt.Sprintf("%q: statement.txt: an error occurs during markdown formating: %s", edir, err))
|
errs = append(errs, fmt.Sprintf("%q: statement.txt: an error occurs during markdown formating: %s", edir, err))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -71,9 +71,9 @@ func SyncThemes(i Importer) []string {
|
|||||||
|
|
||||||
// Extract theme's label
|
// Extract theme's label
|
||||||
if f := strings.Index(tdir, "-"); f >= 0 {
|
if f := strings.Index(tdir, "-"); f >= 0 {
|
||||||
tname = tdir[f+1:]
|
tname = fixnbsp(tdir[f+1:])
|
||||||
} else {
|
} else {
|
||||||
tname = tdir
|
tname = fixnbsp(tdir)
|
||||||
}
|
}
|
||||||
|
|
||||||
if authors, err = getAuthors(i, tdir); err != nil {
|
if authors, err = getAuthors(i, tdir); err != nil {
|
||||||
@ -83,7 +83,7 @@ func SyncThemes(i Importer) []string {
|
|||||||
errs = append(errs, fmt.Sprintf("%q: unable to get theme's overview: %s", tname, err))
|
errs = append(errs, fmt.Sprintf("%q: unable to get theme's overview: %s", tname, err))
|
||||||
} else {
|
} else {
|
||||||
// Split headline from intro
|
// Split headline from intro
|
||||||
ovrvw := strings.Split(intro, "\n")
|
ovrvw := strings.Split(fixnbsp(intro), "\n")
|
||||||
headline = ovrvw[0]
|
headline = ovrvw[0]
|
||||||
if len(ovrvw) > 1 {
|
if len(ovrvw) > 1 {
|
||||||
intro = strings.Join(ovrvw[1:], "\n")
|
intro = strings.Join(ovrvw[1:], "\n")
|
||||||
|
Loading…
Reference in New Issue
Block a user