Beispiel #1
0
        public News GetSingle(object id)
        {
            var path   = GlobalizationFileFinder.GetFilePathById(_path, id.ToString(), _lang);
            var md     = File.ReadAllText(path);
            var result = AnnotationParser.Parse(md);

            return(new News
            {
                Id = id.ToString(),
                Title = result.Annotations.ContainsKey("Title") ? result.Annotations["Title"] : null,
                PublishedAt = result.Annotations.ContainsKey("Published at") ? Convert.ToDateTime(result.Annotations["Published at"]) : DateTime.MinValue,
                IsPinned = result.Annotations.ContainsKey("Pinned") ? Convert.ToBoolean(result.Annotations["Pinned"]) : false,
                Content = result.PlainMarkdown
            });
        }
Beispiel #2
0
        private static RubyParser.TokenVisitor CreateTokenVisitor(FormattedTextBuffer buffer)
        {
            var visitor = new RubyParser.TokenVisitor
            {
                OnNormal = text =>
                {
                    var tokens2 = AnnotationParser.Parse(text);
                    foreach (var token2 in tokens2)
                    {
                        token2.Accept(new AnnotationParser.TokenVisitor
                        {
                            OnBody        = bodyText => buffer.Append(bodyText),
                            OnPlaceholder = () => buffer.Append(AozoraBunko.SpecialCharacters.ExternalCharacterPlaceholder),
                            OnAnnotation  = annotationText =>
                            {
                                //見出し
                                var headingText = HeadingParser.Parse(annotationText);
                                if (headingText != null)
                                {
                                    //TODO: 見出しレベル
                                    buffer.HeadingTitle = headingText;
                                    return;
                                }

                                //圏点
                                var emphasysDottedText = EmphasysDotsParser.Parse(annotationText);
                                if (emphasysDottedText != null)
                                {
                                    buffer.EmphasysDot(buffer.Length - emphasysDottedText.Length, buffer.Length);
                                    return;
                                }

                                //TODO: その他の注記
                            }
                        });
                    }
                    ;
                },
                OnRuby = (baseText, rubyText) =>
                {
                    buffer.Append(baseText);
                    buffer.Ruby(buffer.Length - baseText.Length, buffer.Length, rubyText);
                }
            };

            return(visitor);
        }