Beispiel #1
0
func Constructor(config map[string]interface{}, cache *registry.Cache) (highlight.Highlighter, error) {
	separator := DefaultSeparator
	separatorVal, ok := config["separator"].(string)
	if ok {
		separator = separatorVal
	}

	fragmenterName, ok := config["fragmenter"].(string)
	if !ok {
		return nil, fmt.Errorf("must specify fragmenter")
	}
	fragmenter, err := cache.FragmenterNamed(fragmenterName)
	if err != nil {
		return nil, fmt.Errorf("error building fragmenter: %v", err)
	}

	formatterName, ok := config["formatter"].(string)
	if !ok {
		return nil, fmt.Errorf("must specify formatter")
	}
	formatter, err := cache.FragmentFormatterNamed(formatterName)
	if err != nil {
		return nil, fmt.Errorf("error building fragment formatter: %v", err)
	}

	return NewHighlighter(fragmenter, formatter, separator), nil
}
Beispiel #2
0
func Constructor(config map[string]interface{}, cache *registry.Cache) (highlight.Highlighter, error) {

	fragmenter, err := cache.FragmenterNamed(simple_fragmenter.Name)
	if err != nil {
		return nil, fmt.Errorf("error building fragmenter: %v", err)
	}

	formatter, err := cache.FragmentFormatterNamed(html_formatter.Name)
	if err != nil {
		return nil, fmt.Errorf("error building fragment formatter: %v", err)
	}

	return simple_highlighter.NewHighlighter(
			fragmenter,
			formatter,
			simple_highlighter.DefaultSeparator),
		nil
}