Przeglądaj źródła

Merge pull request #2220 from visuddhinanda/laravel

术语第一次出现,才显示脚注
visuddhinanda 1 rok temu
rodzic
commit
62ec614b13

+ 2 - 1
app/Console/Commands/ExportArticle.php

@@ -18,7 +18,7 @@ class ExportArticle extends Command
     /**
      * The name and signature of the console command.
      * php artisan export:article 78c22ad3-58e2-4cf0-b979-67783ca3a375 123 --channel=7fea264d-7a26-40f8-bef7-bc95102760fb --format=html
-     * php artisan export:article df6c6609-6fc1-42d0-9ef1-535ef3e702c9 1234 --channel=7fea264d-7a26-40f8-bef7-bc95102760fb --anthology=697c9169-cb9d-4a60-8848-92745e467bab --token=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzUxMiJ9.eyJuYmYiOjE2OTc3Mjg2ODUsImV4cCI6MTcyOTI2NDY4NSwidWlkIjoiYmE1NDYzZjMtNzJkMS00NDEwLTg1OGUtZWFkZDEwODg0NzEzIiwiaWQiOjR9.fiXhnY2LczZ9kKVHV0FfD3AJPZt-uqM5wrDe4EhToVexdd007ebPFYssZefmchfL0mx9nF0rgHSqjNhx4P0yDA --format=html
+     * php artisan export:article df6c6609-6fc1-42d0-9ef1-535ef3e702c9 1234 --origin=true --channel=7fea264d-7a26-40f8-bef7-bc95102760fb  --format=docx --anthology=697c9169-cb9d-4a60-8848-92745e467bab --token=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzUxMiJ9.eyJuYmYiOjE2OTc3Mjg2ODUsImV4cCI6MTcyOTI2NDY4NSwidWlkIjoiYmE1NDYzZjMtNzJkMS00NDEwLTg1OGUtZWFkZDEwODg0NzEzIiwiaWQiOjR9.fiXhnY2LczZ9kKVHV0FfD3AJPZt-uqM5wrDe4EhToVexdd007ebPFYssZefmchfL0mx9nF0rgHSqjNhx4P0yDA
      * @var string
      */
     protected $signature = 'export:article {id} {query_id} {--token=} {--anthology=} {--channel=}  {--origin=false} {--translation=true} {--format=tex} {--debug}';
@@ -135,6 +135,7 @@ class ExportArticle extends Command
                 'anthology'=> $this->option('anthology'),
                 'channel' => $this->option('channel'),
                 'origin' => $this->option('origin'),
+                'paragraph' => true,
         ];
         Log::debug('export article http request',['url'=>$url,'param'=>$urlParam]);
         if($this->option('token')){

+ 4 - 3
app/Http/Api/TemplateRender.php

@@ -366,7 +366,8 @@ class TemplateRender{
             case 'markdown':
                 if(isset($props["meaning"])){
                     $key = 'term-'.$props["word"];
-                    if(isset($GLOBALS[$key])){
+                    if(isset($GLOBALS[$key]) && $GLOBALS[$key]===1){
+                        $GLOBALS[$key]++;
                         $output = $props["meaning"];
                     }else{
                         $GLOBALS[$key] = 1;
@@ -375,8 +376,8 @@ class TemplateRender{
                 }else{
                     $output = $props["word"];
                 }
-                //如果有内容,显示为脚注
-                if(!empty($props["note"])){
+                //如果有内容且第一次出现,显示为脚注
+                if(!empty($props["note"]) && $GLOBALS[$key]===1){
                     if(isset($GLOBALS['note_sn'])){
                         $GLOBALS['note_sn']++;
                     }else{

+ 10 - 28
app/Http/Controllers/CorpusController.php

@@ -724,34 +724,16 @@ class CorpusController extends Controller
                                                 });
                             break;
                         default:
-                        /**
-                         * 译文需要markdown渲染
-                         * 包涵术语的不用cache
-                         */
-                            if(strpos($row->content,'[[')===false){
-                                $newSent['html'] = MdRender::render($row->content,[$row->channel_uid],
-                                                            null,$mode,'translation',
-                                                            $row->content_type,$format);
-                                /*
-                                RedisClusters::remember("/sent/{$channelId}/{$currSentId}/{$format}",
-                                                    config('mint.cache.expire'),
-                                                function() use($row,$mode,$format){
-                                                    return MdRender::render($row->content,[$row->channel_uid],
-                                                                            null,$mode,'translation',
-                                                                            $row->content_type,$format);
-                                                });
-                                            */
-                            }else{
-                                $mdRender = new MdRender(
-                                    [
-                                        'debug'=>$this->debug,
-                                        'format'=>$format,
-                                        'mode'=>$mode,
-                                        'channelType'=>'translation',
-                                        'contentType'=>$row->content_type,
-                                    ]);
-                                $newSent['html'] = $mdRender->convert($row->content,[$row->channel_uid]);
-                            }
+                            $options = [
+                                    'debug'=>$this->debug,
+                                    'format'=>$format,
+                                    'mode'=>$mode,
+                                    'channelType'=>'translation',
+                                    'contentType'=>$row->content_type,
+                            ];
+                            $mdRender = new MdRender($options);
+                            $newSent['html'] = $mdRender->convert($row->content,[$row->channel_uid]);
+                            Log::debug('md render',['content'=>$row->content,'options'=>$options,'render'=>$newSent['html']]);
                             break;
                     }
                 }

+ 1 - 0
app/Http/Resources/ArticleResource.php

@@ -201,6 +201,7 @@ class ArticleResource extends JsonResource
                 'format'=> $format,
                 'footnote' => true,
                 'origin' => $request->get('origin',true),
+                'paragraph' => $request->get('paragraph',false),
             ]);
             //Log::debug('article render',['content'=>$this->content,'format'=>$format,'html'=>$html]);
             $data["html"] = $htmlRender->convert($this->content,$channels);